Attempting to use a variable after its ownership has been moved.
Rust enforces memory safety via ownership rules. Types that do not implement the `Copy` trait (like `String` or `Vec`) move their ownership when assigned or passed to a function. Once moved, the original variable cannot be accessed.
Passing a `String` into a function by value, assigning a non-Copy variable to another variable, or using a moved value inside a loop.
1fn print_greeting(name: String) {2 println!("Hello, {}!", name);3}4 5fn main() {6 let s = String::from("Rustacean");7 print_greeting(s); // Ownership of 's' moves into print_greeting8 9 // ERROR E0382: 's' moved on previous line!10 println!("Length is: {}", s.len());11}1// Fix 1: Pass a reference (&str or &String) instead of taking ownership2fn print_greeting(name: &str) {3 println!("Hello, {}!", name);4}5 6fn main() {7 let s = String::from("Rustacean");8 print_greeting(&s); // Pass read-only reference9 10 // Allowed! 's' still retains ownership11 println!("Length is: {}", s.len()); // 912}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
`String` does not implement `Copy`. When passed to `print_greeting(s)`, ownership of `s` moves. The subsequent call `s.len()` fails at compile time because `s` no longer owns memory.