Hey, sorry for the late reply, but I hope a response here can help any future learners with the same question:
The issue is that longest() only returns a reference. It doesn’t create a new String or move ownership. If longest() decides “string2” is the longer of the two, it hands back a reference to data still owned by string2. When string2 goes out of scope, that data’s gone, and result becomes a dangling reference. Rust complains because it can’t guarantee that “string2” will stay alive long enough to safely cover the lifetime of result. If longest() returned an owned String instead of a reference, it wouldn’t be a problem because the returned string would have its own ownership. But returning a reference means you have to ensure the underlying data is still around for as long as that reference is in use.