Remove the synthetic "region bound" from closures and instead update how

type-outlives works for closure types so that it ensures that all upvars
outlive the region in question. This gives the same guarantees but
without introducing artificial regions (and gives better error messages
to boot).
This commit is contained in:
Niko Matsakis 2015-02-28 19:34:16 -05:00
parent c5142056f7
commit 00fcf79448
28 changed files with 93 additions and 230 deletions

View file

@ -14,7 +14,9 @@
fn id<T>(t: T) -> T { t }
fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
id(box || *v) //~ ERROR cannot infer
id(box || *v)
//~^ ERROR `v` does not live long enough
//~| ERROR cannot move out of borrowed content
}
fn main() {

View file

@ -18,7 +18,7 @@ fn borrowed_proc<'a>(x: &'a isize) -> Box<FnMut()->(isize) + 'a> {
fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> {
// This is illegal, because the region bound on `proc` is 'static.
box move|| { *x } //~ ERROR cannot infer
box move|| { *x } //~ ERROR captured variable `x` does not outlive the enclosing closure
}
fn main() { }

View file

@ -20,9 +20,9 @@ fn box_it<'r>(x: Box<FnMut() + 'r>) -> closure_box<'r> {
}
fn main() {
let cl_box = {
let mut cl_box = {
let mut i = 3;
box_it(box || i += 1) //~ ERROR cannot infer
box_it(box || i += 1) //~ ERROR `i` does not live long enough
};
cl_box.cl.call_mut(());
}

View file

@ -13,9 +13,10 @@ use std::thread;
fn main() {
let bad = {
let x = 1;
let y = &x;
let y = &x; //~ ERROR `x` does not live long enough
thread::scoped(|| { //~ ERROR cannot infer an appropriate lifetime
thread::scoped(|| {
//~^ ERROR `y` does not live long enough
let _z = y;
})
};

View file

@ -15,6 +15,6 @@
fn main() {
let _f = {
let x = 0_usize;
|| x //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
|| x //~ ERROR `x` does not live long enough
};
}