Curriculum Ownership & borrowing Moves and Copy exercise 2 · mcq-explain
Moves and Copy
rustc emits this diagnostic on the program below. Pick the line
that's a MOVE (not a copy, borrow, or unrelated assignment).
error[E0382]: borrow of moved value: name
--> src/main.rs:3:20
|
1 | let name = String::from("paul");
2 | let owner = name;
3 | println!("{}", name);
| ^^^^ value borrowed here after move
About this theme
TypeScript variables point at values managed by a garbage collector; Rust bindings own values unless the type is Copy. This theme makes moves concrete before references appear. Planned exercises: 1. choose which binding owns a String. 2. recognise a move. 3. recognise a Copy integer. 4. fill the line that avoids using a moved value. 5. fill a clone() only where an owned duplicate is intended. 6. write a function that takes ownership. 7. write a function that returns ownership. 8. translate TS object passing into Rust moves. 9. fix a use-after-move compiler error.