why are self referential structs disallowed?

74 points Signal_Way_2559 53 comments

So i was reading "Learning Rust With Entirely Too Many Linked Lists" and came across this :-

struct List<'a, T> {

head: Link<T>,

tail: Option<&'a mut Node<T>>,

}

i am a complete beginner and unable to understand why is this bad. If List is ever moved why would tail become invalid if the reference to Node<T> inside tail is behind a box. Let's say if data inside Box moves and we Pin it why would it still be unsafe. I just cannot wrap my head around lifetimes here can anybody explain with a simple example maybe?