Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Equivalent?
rustc: i686-pc-mingw32/stage2/test/collectionstest-i686-pc-mingw32.exe
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864:14: 864:23 error: cannot borrow `cur#0` as mutable more than once at a time
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864 Some(ref mut x) => {
^~~~~~~~~
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864:14: 864:23 note: previous borrow of `cur#0` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `cur#0` until the borrow ends
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864 Some(ref mut x) => {
^~~~~~~~~
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:874:2: 874:2 note: previous borrow ends here
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:860 -> Option<&'r mut V> {
...
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:874 }
^
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:866:22: 866:39 error: cannot assign to `cur` because it is borrowed
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:866 Less => {cur = &mut x.left}
^~~~~~~~~~~~~~~~~
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864:14: 864:23 note: borrow of `cur` occurs here
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864 Some(ref mut x) => {
^~~~~~~~~
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:867:25: 867:43 error: cannot assign to `cur` because it is borrowed
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:867 Greater => {cur = &mut x.right},
^~~~~~~~~~~~~~~~~~
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864:14: 864:23 note: borrow of `cur` occurs here
C:\Users\Alexis\Documents\GitHub\rust\src\libcollections\treemap.rs:864 Some(ref mut x) => {
^~~~~~~~~
error: aborting due to 3 previous errors
fn find_mut<'r, K: Ord, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
key: &K)
-> Option<&'r mut V> {
let mut cur = node;
loop {
match *cur {
Some(ref mut x) => {
match key.cmp(&x.key) {
Less => {cur = &mut x.left}
Greater => {cur = &mut x.right},
Equal => return Some(&mut x.value),
}
}
None => return None
}
}
}
fn find_mut<'r, K: Ord, V>(node: &'r mut Option<Box<TreeNode<K, V>>>,
key: &K)
-> Option<&'r mut V> {
match *node {
Some(ref mut x) => {
match key.cmp(&x.key) {
Less => find_mut(&mut x.left, key),
Greater => find_mut(&mut x.right, key),
Equal => Some(&mut x.value),
}
}
None => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.