Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Created September 14, 2014 23:53
Show Gist options
  • Save makoConstruct/336a91ddb06c1b17bca4 to your computer and use it in GitHub Desktop.
Save makoConstruct/336a91ddb06c1b17bca4 to your computer and use it in GitHub Desktop.
Possible bug about an inconsistency between borrowing from boxeds and borrowing from &muts
struct Thing{ a: u8, b: u8 }
fn main(){
let mut boxed_thing = box Thing{a:2, b:2};
let btr = &mut boxed_thing;
let mut unboxed_thing = Thing{a:3, b:3};
let utr = &mut unboxed_thing;
fn pass(a:&mut u8, b:&mut u8){}
pass(&mut utr.a, &mut utr.b); //< this is allowed
pass(&mut btr.a, &mut btr.b); //< while this is not.
//error: cannot borrow `btr.b` as mutable more than once at a time
//note: previous borrow of `btr.a` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `btr.a` until the borrow ends
//pass(&mut btr.a, &mut btr.b); //< while this is not. "
// ^~~~~
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment