Skip to content

Instantly share code, notes, and snippets.

@phildawes
Created October 28, 2014 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phildawes/a6f99b1fb5c3966ecb14 to your computer and use it in GitHub Desktop.
Save phildawes/a6f99b1fb5c3966ecb14 to your computer and use it in GitHub Desktop.
mutating a field after move
struct Foo {
name: String
}
impl Drop for Foo {
fn drop(&mut self) {
println!("dropped");
}
}
fn another_fn(f: Foo) {
println!("f name is {}",f.name);
}
fn main() {
let mut f = Foo {name: "myname".to_string()};
another_fn(f); // f 'moved' to another_fn
f.name = "another name".to_string(); // why am I allowed to do this?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment