fn main() {
let s = String::from("hi");
let t = s;
println!("{} {}", s, t);
}What does the compiler report?
- aIt prints
hi hi;let t = scopies the string bytes intot - bError E0499:
sandtare two mutable owners of the same heap buffer - cError E0382:
swas moved intotand is used afterwards✓ - dIt compiles and prints
hionce;sbecomes an empty string after the assignment
Explanation:
String owns a heap buffer and is not Copy, so let t = s moves ownership to t. The compiler then rejects the later read of s with E0382 (borrow of moved value). Nothing is copied and s does not become empty; it is simply no longer usable.