Reading "The Rustonomicon" I found this example/explanation:
Actually passing references to outer scopes will cause Rust to infer a larger lifetime:
let x = 0;
let z;
let y = &x;
z = y;
The book explains that preceeding statements are equivalent to the following:
'a: {
let x: i32 = 0;
'b: {
let z: &'b i32;
'c: {
// Must use 'b here because the reference to x is
// being passed to the scope 'b.
let y: &'b i32 = &'b x;
z = y;
}
}
}
Can you explain the reason behind this rule?
What is the reason that led to formulating it?
I'm an absolute beginner but I want to try to understand the rationale rather than just memorizing.
Thank you for your time