Skip to content

Instantly share code, notes, and snippets.

@eevee
Created October 3, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eevee/3829449 to your computer and use it in GitHub Desktop.
Save eevee/3829449 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(++_argv: ~[~str]) {
let mut choices: ~[Choice] = ~[Many(HashMap())];
for vec::each_mut(choices) |choice| {
match *choice {
Many(opts) => {
if opts.size() == 1 {
*choice = One(vec_from_set(opts)[0]);
}
}
One(_) => {}
}
}
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