Attempting to assign a new value to a mutable variable while active borrowed references exist.
This error occurs when you attempt to reassign or modify an owned variable that is currently borrowed immutably or mutably by another reference.
Modifying a variable while a reference is still active in a print statement or function call later in the scope.
1fn main() {2 let mut x = 5;3 let y = &x; // x is borrowed immutably by y4 x = 10; // ERROR E0506: cannot assign to 'x' because it is borrowed!5 println!("y: {}", y); // y is used here6}1fn main() {2 let mut x = 5;3 let y = x; // Fix 1: Copy/clone value if type is Copy4 x = 10; // Allowed5 println!("y: {}", y);6 7 // Fix 2: Or limit reference scope so it drops before mutation8 let mut a = 5;9 {10 let b = &a;11 println!("b: {}", b); // b's lifetime ends here12 }13 a = 10; // Allowed: reference b is no longer active14}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The compiler must guarantee that the reference y remains valid and points to unchanged data. Modifying x = 10 while y is still active violates this safety invariant, causing E0506.