Skip to content

Instantly share code, notes, and snippets.

@ezyang
Last active December 30, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ezyang/7886849 to your computer and use it in GitHub Desktop.
Save ezyang/7886849 to your computer and use it in GitHub Desktop.
pub unsafe fn alloc_mega_group(mblocks: nat) -> ~Block {
let n = MBLOCK_GROUP_BLOCKS(mblocks);
let mut prev_link = &mut free_mblock_list.p;
let mut best: Option<(&mut BlockData, &mut BlockMeta)> = None;
loop {
match prev_link {
&None => break,
// NB: need to match it out, so we don't take out a
// reference on prev_link that will interfere with the
// take()
&Some(~Block {meta: BlockMeta {blocks, ..}, ..}) if blocks as uint == n => {
let mut bd = prev_link.take_unwrap();
*prev_link = bd.link.p.take();
return bd
},
&Some(ref mut bd) => {
if bd.meta.blocks as uint > n && match best {
None => true,
Some((_, ref best_meta)) => bd.meta.blocks < best_meta.blocks
} {
best = Some((&mut bd.data, &mut bd.meta))
}
prev_link = &mut bd.link.p;
}
}
}
match best {
None => fail!("ni"),
Some((data, meta)) => fail!("ni")
}
}
~~~~
BlockAlloc.rs|249 col 33 error| cannot borrow `*prev_link` as mutable more than once at a time
BlockAlloc.rs|253 col 22 n| second borrow of `*prev_link` as mutable occurs here
BlockAlloc.rs|250 col 20 error| cannot assign to `*prev_link` because it is borrowed
BlockAlloc.rs|253 col 22 n| borrow of `*prev_link` occurs here
BlockAlloc.rs|253 col 22 error| cannot borrow `(*prev_link)#0` as mutable more than once at a time
BlockAlloc.rs|253 col 22 n| second borrow of `(*prev_link)#0` as mutable occurs here
BlockAlloc.rs|260 col 20 error| cannot assign to `prev_link` because it is borrowed
BlockAlloc.rs|253 col 22 n| borrow of `prev_link` occurs here
|| error: aborting due to 4 previous errors
|| task 'rustc' failed at 'explicit failure', /build/buildd/rust-nightly-201312090405~898d2c3~saucy/src/libsyntax/diagnostic.rs:102
|| task '<main>' failed at 'explicit failure', /build/buildd/rust-nightly-201312090405~898d2c3~saucy/src/librustc/lib.rs:393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment