rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.74k stars 256 forks source link

Confused about lifetime #442

Open 7lon7 opened 4 months ago

7lon7 commented 4 months ago
let x = 0;
let z;
let y = &x;
z = y;
'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;
        }
    }
}

Why mark y with 'b, but not z with 'c? Are there any references on lifetime eval?