When you define a structure, you do not establish a connection between the lifetime of the structure and the lifetime of the fields. As you pointed out, links in fields should live longer than structure.
Instead, you provide a “total lifetime” that will be specialized in creating the structure. This is similar to having a structure with a type parameter:
struct Foo<T> foo: T, }
When you create the structure, the compiler inserts the appropriate lifetimes (or types), and then checks that everything is still working.
Another thing is that you can specify the lifetime relative to each other:
struct Line<'a, 'b: 'a> { start: &'a Point, end: &'b Point, }
This suggests that start and end can have different lifetimes if end lifetimes exceed start times.
why doesn't the compiler make a lifetime exception for structures? Rust seems to do
(my emphasis)
I actually believe that Rust tends to be explicit, especially when it comes to defining top-level elements (such as functions, structures).
The rules for choosing a life cycle for functions have a rather small scope and were found empirically in RFC 141 with a high probability of success (87%). It was a very good ergonomic return on investment.
Perhaps at some point a similar deviation will occur for the structures, but this was not a big enough problem. If you are strongly interested in this, then I highly recommend that you seek consensus on the user forum , go to the developer forum, and ultimately make an RFC.
RFC 2093 adds a small number of findings. Before implementing it, you must specify that the generic type must survive the link as a link:
struct Foo<'a, T: 'a> { start: &'a T, }
There is no case where you don’t want this boundary, so after implementing the RFC, you can simply say:
struct Foo<'a, T> { start: &'a T, }