Created
December 16, 2013 10:37
-
-
Save ezyang/7985095 to your computer and use it in GitHub Desktop.
This file contains 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
#[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