Last active
August 29, 2015 14:03
-
-
Save Gankra/277ff3d2c83340173c47 to your computer and use it in GitHub Desktop.
Equivalent?
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
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 |
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
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 | |
} | |
} | |
} |
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
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