Skip to content

Instantly share code, notes, and snippets.

@tmerr
Created July 13, 2015 20:47
Show Gist options
  • Select an option

  • Save tmerr/f5dc0a3ac0e614d1314a to your computer and use it in GitHub Desktop.

Select an option

Save tmerr/f5dc0a3ac0e614d1314a to your computer and use it in GitHub Desktop.

Revisions

  1. tmerr created this gist Jul 13, 2015.
    24 changes: 24 additions & 0 deletions gistfile1.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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