Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created December 13, 2012 20:18
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 bstrie/4279444 to your computer and use it in GitHub Desktop.
Save bstrie/4279444 to your computer and use it in GitHub Desktop.
struct A {
v :~[int],
}
impl A {
fn foo(&mut self) {
//error: illegal borrow unless pure: unique value in aliasable, mutable location
let pa = &mut self.v[1];
//note: impure due to assigning to dereference of mutable & pointer
*pa = 5;
}
}
fn main() {
let mut a = A{v:~[1,2,3]};
{ //that compiles fine
let pb = &mut a.v[1];
*pb = 6;
}
a.foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment