Skip to content

Better lifetime error message #56479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) {
let mut diag = infcx.tcx.sess.struct_span_err(
span,
"unsatisfied lifetime constraints", // FIXME
"lifetime may not live long enough"
);

let counter = &mut 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) i32))
]

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/escape-argument-callee.rs:26:45
|
LL | let mut closure = expect_sig(|p, y| *p = y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LL | | },
= note: late-bound region is '_#5r
= note: late-bound region is '_#6r

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/propagate-approximated-fail-no-postdom.rs:46:13
|
LL | |_outlives1, _outlives2, _outlives3, x, y| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ 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| {

// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ note: External requirements
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | //~^ ERROR lifetime may not live long enough
LL | | });
| |_____^
|
Expand All @@ -24,17 +23,17 @@ 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 | |
LL | | // Only works if 'x: 'y:
... |
LL | | demand_y(x, y, x.get())
LL | | //~^ ERROR lifetime may not live long enough
LL | | });
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:46:9
error: lifetime may not live long enough
--> $DIR/propagate-approximated-ref.rs:45:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ 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| {

// Only works if 'x: 'y:
demand_y(outlives1, outlives2, x.get())
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ note: External requirements
|
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| _____________________________________________^
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(outlives1, outlives2, x.get())
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | //~^ ERROR lifetime may not live long enough
LL | | });
| |_____^
|
Expand All @@ -24,17 +23,17 @@ 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 | |
LL | | // Only works if 'x: 'y:
... |
LL | | demand_y(outlives1, outlives2, x.get())
LL | | //~^ ERROR lifetime may not live long enough
LL | | });
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:39:9
error: lifetime may not live long enough
--> $DIR/propagate-approximated-val.rs:38:9
|
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LL | | });
= note: late-bound region is '_#2r
= note: late-bound region is '_#3r

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:37:9
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LL | | });
= note: late-bound region is '_#3r
= note: late-bound region is '_#4r

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:41:9
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/region-lbr-named-does-not-outlive-static.rs:9:5
|
LL | fn foo<'a>(x: &'a u32) -> &'static u32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 {
&*x
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

fn main() { }
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/region-lbr1-does-not-outlive-ebr2.rs:9:5
|
LL | fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | expect_sig(|a, b| b); // ought to return `a`
for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) i32)) -> &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) i32
]

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/return-wrong-bound-region.rs:11:23
|
LL | expect_sig(|a, b| b); // ought to return `a`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/issue-48238.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/issue-48238.rs:11:13
|
LL | move || use_val(&orig); //~ ERROR
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/issue-50716.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/issue-50716.rs:16:14
|
LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)
Expand Down
9 changes: 4 additions & 5 deletions src/test/ui/nll/issue-52113.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#![allow(warnings)]
#![feature(nll)]

trait Bazinga { }
impl<F> Bazinga for F { }
trait Bazinga {}
impl<F> Bazinga for F {}

fn produce1<'a>(data: &'a u32) -> impl Bazinga + 'a {
let x = move || {
Expand All @@ -21,7 +21,6 @@ fn produce2<'a>(data: &'a mut Vec<&'a u32>, value: &'a u32) -> impl Bazinga + 'a
x
}


fn produce3<'a, 'b: 'a>(data: &'a mut Vec<&'a u32>, value: &'b u32) -> impl Bazinga + 'a {
let x = move || {
let value: &'a u32 = value;
Expand All @@ -35,7 +34,7 @@ fn produce_err<'a, 'b: 'a>(data: &'b mut Vec<&'b u32>, value: &'a u32) -> impl B
let value: &'a u32 = value;
data.push(value);
};
x //~ ERROR unsatisfied lifetime constraints
x //~ ERROR lifetime may not live long enough
}

fn main() { }
fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/nll/issue-52113.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: unsatisfied lifetime constraints
--> $DIR/issue-52113.rs:38:5
error: lifetime may not live long enough
--> $DIR/issue-52113.rs:37:5
|
LL | fn produce_err<'a, 'b: 'a>(data: &'b mut Vec<&'b u32>, value: &'a u32) -> impl Bazinga + 'b {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | x //~ ERROR unsatisfied lifetime constraints
LL | x //~ ERROR lifetime may not live long enough
| ^ returning this value requires that `'a` must outlive `'b`

error: aborting due to previous error
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/nll/issue-52742.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ struct Foo<'a, 'b> {
}

struct Bar<'b> {
z: &'b u32
z: &'b u32,
}

impl Foo<'_, '_> {
fn take_bar(&mut self, b: Bar<'_>) {
self.y = b.z
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}
}

fn main() { }
fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/nll/issue-52742.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/issue-52742.rs:15:9
|
LL | fn take_bar(&mut self, b: Bar<'_>) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/issue-55394.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Foo<'s> {

impl Foo<'_> {
fn new(bar: &mut Bar) -> Self {
Foo { bar } //~ ERROR unsatisfied lifetime constraints
Foo { bar } //~ERROR lifetime may not live long enough
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/issue-55394.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/issue-55394.rs:11:9
|
LL | fn new(bar: &mut Bar) -> Self {
| - ---- return type is Foo<'2>
| |
| let's call the lifetime of this reference `'1`
LL | Foo { bar } //~ ERROR unsatisfied lifetime constraints
LL | Foo { bar } //~ERROR lifetime may not live long enough
| ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`

error: aborting due to previous error
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/issue-55401.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/issue-55401.rs:5:5
|
LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fn bar<'a, 'b>() -> fn(&'a u32, &'b u32) -> &'a u32 {
let g: fn(_, _) -> _ = |_x, y| y;
g
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_closure.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/mir_check_cast_closure.rs:7:5
|
LL | fn bar<'a, 'b>() -> fn(&'a u32, &'b u32) -> &'a u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_reify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn bar<'a>(x: &'a u32) -> &'static u32 {
// as part of checking the `ReifyFnPointer`.
let f: fn(_) -> _ = foo;
f(x)
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_reify.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/mir_check_cast_reify.rs:37:5
|
LL | fn bar<'a>(x: &'a u32) -> &'static u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_unsafe_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
// in `g`. These are related via the `UnsafeFnPointer` cast.
let g: unsafe fn(_) -> _ = f;
unsafe { g(input) }
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_unsafe_fn.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/mir_check_cast_unsafe_fn.rs:9:14
|
LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::Debug;

fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
x
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/nll/mir_check_cast_unsize.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/mir_check_cast_unsize.rs:8:5
|
LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:45:39
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
Expand Down Expand Up @@ -94,7 +94,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
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:56:39
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LL | | }
T
]

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/projection-one-region-trait-bound-closure.rs:37:39
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
Expand Down Expand Up @@ -76,7 +76,7 @@ LL | | }
T
]

error: unsatisfied lifetime constraints
error: lifetime may not live long enough
--> $DIR/projection-one-region-trait-bound-closure.rs:47:39
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
T: Anything<'b, 'b>,
{
with_signature(cell, t, |cell, t| require(cell, t));
//~^ ERROR unsatisfied lifetime constraints
//~^ ERROR lifetime may not live long enough
}

#[rustc_regions]
Expand Down
Loading