A borrowed reference outlives the value it references.
Rust ensures references never point to freed memory (dangling references). E0597 occurs when a borrowed reference is held past the scope where the original owned value is dropped.
Storing a reference to a temporary variable created inside an inner block or function.
1fn main() {2 let r;3 {4 let x = 5;5 r = &x; // ERROR E0597: 'x' does not live long enough6 } // 'x' dropped here!7 println!("r: {}", r); // 'r' used here8}1fn main() {2 let x = 5; // Declare 'x' in outer scope3 let r = &x;4 println!("r: {}", r); // Safe!5}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
`x` goes out of scope at the end of the inner block. `r` holds a reference to `x` beyond that scope, creating a potential dangling pointer.