Created
July 13, 2015 20:47
-
-
Save tmerr/f5dc0a3ac0e614d1314a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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