nomicon icon indicating copy to clipboard operation
nomicon copied to clipboard

Confused about lifetime

Open 7lon7 opened this issue 1 year ago • 0 comments

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?

7lon7 avatar Mar 03 '24 09:03 7lon7