libstd: changes to in response to #5656

This commit is contained in:
Niko Matsakis
2013-04-10 13:14:06 -07:00
parent 61b9e0ebfa
commit 03396473b8
7 changed files with 390 additions and 14 deletions

View File

@@ -55,7 +55,7 @@ pub impl<A:Copy> Future<A> {
}
pub impl<A> Future<A> {
#[cfg(stage0)]
fn get_ref(&self) -> &'self A {
/*!
* Executes the future's closure and then returns a borrowed
@@ -80,6 +80,34 @@ pub impl<A> Future<A> {
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn get_ref<'a>(&'a self) -> &'a A {
/*!
* Executes the future's closure and then returns a borrowed
* pointer to the result. The borrowed pointer lasts as long as
* the future.
*/
unsafe {
match self.state {
Forced(ref mut v) => { return cast::transmute(v); }
Evaluating => fail!(~"Recursive forcing of future!"),
Pending(_) => {}
}
let mut state = Evaluating;
self.state <-> state;
match state {
Forced(_) | Evaluating => fail!(~"Logic error."),
Pending(f) => {
self.state = Forced(f());
self.get_ref()
}
}
}
}
}
pub fn from_value<A>(val: A) -> Future<A> {