Auto merge of #54798 - matthewjasper:free-region-closure-errors, r=nikomatsakis

[NLL]  Improve closure region bound errors

Previously, we would report free region errors that originate from closure with the span of the closure and a "closure body requires ..." message. This is now updated to use a reason and span from inside the closure.
This commit is contained in:
bors 2018-10-09 07:22:14 +00:00
commit 607243b6f9
26 changed files with 300 additions and 210 deletions

View file

@ -1,13 +1,11 @@
error: unsatisfied lifetime constraints
--> $DIR/issue-10291.rs:12:65
--> $DIR/issue-10291.rs:13:9
|
LL | fn test<'x>(x: &'x isize) {
| -- lifetime `'x` defined here
LL | drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
| _________________________________________________________________^
LL | | x //~ ERROR E0312
LL | | }));
| |_____^ closure body requires that `'x` must outlive `'static`
LL | fn test<'x>(x: &'x isize) {
| -- lifetime `'x` defined here
LL | drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
LL | x //~ ERROR E0312
| ^ returning this value requires that `'x` must outlive `'static`
error: aborting due to previous error

View file

@ -51,10 +51,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR unsatisfied lifetime constraints
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR unsatisfied lifetime constraints
});
}

View file

@ -3,10 +3,10 @@ note: External requirements
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |_____^
|
@ -24,8 +24,8 @@ note: No external requirements
|
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
... |
LL | | });
LL | | }
@ -34,20 +34,15 @@ LL | | }
= note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
error: unsatisfied lifetime constraints
--> $DIR/propagate-approximated-ref.rs:53:47
--> $DIR/propagate-approximated-ref.rs:56:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | });
| |_____^ closure body requires that `'a` must outlive `'b`
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
error: aborting due to previous error

View file

@ -44,10 +44,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
//~^ ERROR borrowed data escapes outside of function
//~| ERROR unsatisfied lifetime constraints
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR unsatisfied lifetime constraints
});
}

View file

@ -4,10 +4,10 @@ note: External requirements
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |_____^
|
@ -26,7 +26,7 @@ note: No external requirements
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
LL | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | |
... |
LL | | });
LL | | }
@ -41,29 +41,23 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------ `cell_a` is a reference that is only valid in the function body
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |______^ `cell_a` escapes the function body here
error: unsatisfied lifetime constraints
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | });
| |_____^ closure body requires that `'a` must outlive `'b`
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
error: aborting due to 2 previous errors

View file

@ -47,9 +47,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR borrowed data escapes outside of function
//~| ERROR unsatisfied lifetime constraints
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR unsatisfied lifetime constraints
});
}

View file

@ -4,9 +4,9 @@ note: External requirements
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |_____^
|
@ -25,7 +25,7 @@ note: No external requirements
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | | // Only works if 'x: 'y:
... |
LL | | });
LL | | }
@ -40,27 +40,22 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------ `cell_a` is a reference that is only valid in the function body
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |______^ `cell_a` escapes the function body here
error: unsatisfied lifetime constraints
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:51:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | | //~^ ERROR borrowed data escapes outside of function
LL | | //~| ERROR unsatisfied lifetime constraints
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | });
| |_____^ closure body requires that `'a` must outlive `'b`
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
error: aborting due to 2 previous errors

View file

@ -44,10 +44,10 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y:
#[rustc_regions]
fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
//~^ ERROR unsatisfied lifetime constraints
// Only works if 'x: 'y:
demand_y(outlives1, outlives2, x.get())
//~^ ERROR unsatisfied lifetime constraints
});
}

View file

@ -3,10 +3,10 @@ note: External requirements
|
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| _____________________________________________^
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(outlives1, outlives2, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | });
| |_____^
|
@ -24,8 +24,8 @@ note: No external requirements
|
LL | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
LL | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
... |
LL | | });
LL | | }
@ -34,20 +34,15 @@ LL | | }
= note: defining type: DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]) with substs []
error: unsatisfied lifetime constraints
--> $DIR/propagate-approximated-val.rs:46:45
--> $DIR/propagate-approximated-val.rs:49:9
|
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| _____________________________________________^
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(outlives1, outlives2, x.get())
LL | | });
| |_____^ closure body requires that `'a` must outlive `'b`
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(outlives1, outlives2, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
error: aborting due to previous error

View file

@ -41,7 +41,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0/0:8 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a))`...
error: unsatisfied lifetime constraints
--> $DIR/projection-one-region-closure.rs:55:29
--> $DIR/projection-one-region-closure.rs:55:39
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -49,7 +49,7 @@ LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
note: External requirements
--> $DIR/projection-one-region-closure.rs:66:29
@ -95,7 +95,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
error: unsatisfied lifetime constraints
--> $DIR/projection-one-region-closure.rs:66:29
--> $DIR/projection-one-region-closure.rs:66:39
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -103,7 +103,7 @@ LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
note: External requirements
--> $DIR/projection-one-region-closure.rs:80:29

View file

@ -32,7 +32,7 @@ LL | | }
]
error: unsatisfied lifetime constraints
--> $DIR/projection-one-region-trait-bound-closure.rs:47:29
--> $DIR/projection-one-region-trait-bound-closure.rs:47:39
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -40,7 +40,7 @@ LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
note: External requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:57:29
@ -77,7 +77,7 @@ LL | | }
]
error: unsatisfied lifetime constraints
--> $DIR/projection-one-region-trait-bound-closure.rs:57:29
--> $DIR/projection-one-region-trait-bound-closure.rs:57:39
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -85,7 +85,7 @@ LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ closure body requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
note: External requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:70:29

View file

@ -21,16 +21,13 @@ LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot in
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
error: unsatisfied lifetime constraints
--> $DIR/regions-addr-of-upvar-self.rs:19:18
--> $DIR/regions-addr-of-upvar-self.rs:20:17
|
LL | pub fn chase_cat(&mut self) {
| - let's call the lifetime of this reference `'1`
LL | let _f = || {
| __________________^
LL | | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
LL | | *p = 3;
LL | | };
| |_________^ closure body requires that `'1` must outlive `'static`
LL | pub fn chase_cat(&mut self) {
| - let's call the lifetime of this reference `'1`
LL | let _f = || {
LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
| ^ type annotation requires that `'1` must outlive `'static`
error[E0597]: `self` does not live long enough
--> $DIR/regions-addr-of-upvar-self.rs:20:46

View file

@ -36,18 +36,13 @@ LL | }
= note: borrowed value must be valid for the static lifetime...
error: unsatisfied lifetime constraints
--> $DIR/regions-nested-fns.rs:23:68
--> $DIR/regions-nested-fns.rs:24:27
|
LL | fn nested<'x>(x: &'x isize) {
| -- lifetime `'x` defined here
LL | fn nested<'x>(x: &'x isize) {
| -- lifetime `'x` defined here
...
LL | ignore::< Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
| ____________________________________________________________________^
LL | | if false { return x; } //~ ERROR E0312
LL | | if false { return ay; }
LL | | return z;
LL | | }));
| |_____^ closure body requires that `'x` must outlive `'static`
LL | if false { return x; } //~ ERROR E0312
| ^ returning this value requires that `'x` must outlive `'static`
error: aborting due to 4 previous errors