-
-
Save pcwalton/3831026 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
extern mod std; | |
use std::map::HashMap; | |
use std::map::Set; | |
use std::map::vec_from_set; | |
enum Choice { | |
Many(Set<int>), | |
One(int), | |
} | |
fn main() { | |
let choices: ~[mutable::Mut<Choice>] = ~[mutable::Mut(Many(HashMap()))]; | |
for vec::each(choices) |choice| { | |
let result = do choice.borrow_imm() |choice| { | |
match *choice { | |
Many(opts) if opts.size() == 1 => Some(vec_from_set(opts)[0]), | |
Many(_) | One(_) => None | |
} | |
}; | |
do option::iter(&result) |result| { | |
do choice.borrow_mut() |choice| { | |
*choice = One(*result); | |
} | |
} | |
} | |
log(error, choices); | |
} |
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
borrowenum.rs:17:17: 17:22 error: illegal borrow unless pure: enum variant in aliasable, mutable location | |
borrowenum.rs:17 Many(opts) => { | |
^~~~~ | |
borrowenum.rs:19:20: 19:27 note: impure due to assigning to dereference of mutable & pointer | |
borrowenum.rs:19 *choice = One(vec_from_set(opts)[0]); | |
^~~~~~~ | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment