Skip to content

Instantly share code, notes, and snippets.

@pcwalton
Forked from eevee/borrowenum.rs
Created October 4, 2012 01:48
Show Gist options
  • Save pcwalton/3831026 to your computer and use it in GitHub Desktop.
Save pcwalton/3831026 to your computer and use it in GitHub Desktop.
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);
}
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