Created
September 14, 2014 23:53
-
-
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
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
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