Skip to content

Instantly share code, notes, and snippets.

@tmerr
Created July 13, 2015 20:47
Show Gist options
  • Save tmerr/f5dc0a3ac0e614d1314a to your computer and use it in GitHub Desktop.
Save tmerr/f5dc0a3ac0e614d1314a to your computer and use it in GitHub Desktop.
fn mutate(s: &mut SomeStruct) {
s.field += 1;
}
struct SomeStruct {
field: i32
}
impl SomeStruct {
fn do_something(&mut self) {
mutate(&mut self);
}
}
fn main() {
let mut some_struct = SomeStruct { field: 3 };
some_struct.do_something();
}
// [tmerr@thegibson stuff]$ rustc thing.rs
// thing.rs:12:21: 12:25 error: cannot borrow immutable local variable `self` as mutable
// thing.rs:12 mutate(&mut self);
// ^~~~
//error: aborting due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment