Lifetime(a) = lifetime(b) iff (a=b)?

Firstly, 2. isn't strictly true, because a) variables can be 'static, and that's really "the same for all", and b) let can bind more than one variable in one statement, and those will also share a lifetime.

Otoh, most of the times, this doesn't matter, and you're basically right. You're looking very closely though, and that's probably not appropriate for an introductory text such as the book. The right way to read it (in my words, as far as I understand it) is this: The signature fn longest<'a>(x: &'a str, y: &'a str) -> &'a str expresses the following:

Every lifetime 'a that's a lower bound for the lifetime of x AND y (that is, both x and y live for the whole duration 'a) is also a lower bound for the lifetime of the returned reference of longest.

Or, the returned reference is valid as long as both of x and y are.

3 Likes