Created
January 31, 2014 11:50
-
-
Save pzol/8730665 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| use std::hashmap::HashMap; | |
| #[test] | |
| fn test(){ | |
| let mut omap: Option<HashMap<~str, uint>> = None; | |
| omap = Some(HashMap::new()); | |
| let must_insert = false; | |
| { | |
| let map = omap.get_mut_ref(); | |
| map.insert(~"foo", 1); | |
| let (v, must_insert) = match map.find_mut(&~"foo") { | |
| Some(c) => (*c, false), | |
| None => (0 as uint, true) | |
| }; | |
| } | |
| if must_insert { | |
| omap.get_mut_ref().insert(~"bar", 2); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:10:20: 10:23 error: cannot borrow
*mapbecause it is already borrowed as mutable/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:10 None => { map.insert(
"bar", 2); 2 },"foo") {^~~
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:9:17: 9:20 note: previous borrow of
*mapas mutable occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of*mapuntil the borrow ends/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:9 let v = match map.find_mut(&
^~~
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:12:4: 12:4 note: previous borrow ends here
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:9 let v = match map.find_mut(&
"foo") {"bar", 2); 2 },/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:10 None => { map.insert(
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:11 Some(c) => 0
/Users/pzol/Dropbox/src/rust/one/src/option_test.rs:12 };
^
error: aborting due to previous error
[Finished in 0.1s with exit code 101]
[cmd: ['/usr/local/bin/rustc', '--test', '-o', '/Users/pzol/Dropbox/src/rust/one/bin/test_option_test', '/Users/pzol/Dropbox/src/rust/one/src/option_test.rs']]
[dir: /Users/pzol/Dropbox/src/rust/one/src]
[path: /usr/bin:/bin:/usr/sbin:/sbin]