Skip to content

Instantly share code, notes, and snippets.

@ezyang
Created December 16, 2013 10:37
Show Gist options
  • Save ezyang/7985095 to your computer and use it in GitHub Desktop.
Save ezyang/7985095 to your computer and use it in GitHub Desktop.
#[allow(dead_code)];
use std::util;
enum List<T> {
Cons(T, ~List<T>),
Nil
}
fn pop<T>(prev: &mut ~List<T>) -> Option<~List<T>> {
let xs = util::replace(match prev {
&~Cons(_, ref mut rs) => rs,
&~Nil => return None
}, ~Nil);
Some(util::replace(prev, xs))
}
/* NB: xs cannot be inlined, see below:
fn pop<T>(prev: &mut ~List<T>) -> Option<~List<T>> {
Some(util::replace(prev, util::replace(match prev {
&~Cons(_, ref mut rs) => rs,
&~Nil => return None // NB: the first replace was a no-op
}, ~Nil)))
}
del.rs|21 col 18 error| cannot borrow `(**prev)#1` as mutable more than once at a time
del.rs|20 col 23 n| second borrow of `(**prev)#1` as mutable occurs here
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment