Skip to content

Commit 53b622a

Browse files
committed
Auto merge of #56479 - mark-i-m:unsat, r=nikomatsakis
Better lifetime error message I propose the following error message as more user-friendly r? @nikomatsakis
2 parents f001287 + db2d243 commit 53b622a

File tree

53 files changed

+90
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+90
-95
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
505505
) {
506506
let mut diag = infcx.tcx.sess.struct_span_err(
507507
span,
508-
"unsatisfied lifetime constraints", // FIXME
508+
"lifetime may not live long enough"
509509
);
510510

511511
let counter = &mut 1;

src/test/ui/nll/closure-requirements/escape-argument-callee.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
99
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))
1010
]
1111

12-
error: unsatisfied lifetime constraints
12+
error: lifetime may not live long enough
1313
--> $DIR/escape-argument-callee.rs:26:45
1414
|
1515
LL | let mut closure = expect_sig(|p, y| *p = y);

src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | | },
1616
= note: late-bound region is '_#5r
1717
= note: late-bound region is '_#6r
1818

19-
error: unsatisfied lifetime constraints
19+
error: lifetime may not live long enough
2020
--> $DIR/propagate-approximated-fail-no-postdom.rs:46:13
2121
|
2222
LL | |_outlives1, _outlives2, _outlives3, x, y| {

src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4141
#[rustc_regions]
4242
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4343
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
44-
4544
// Only works if 'x: 'y:
4645
demand_y(x, y, x.get())
47-
//~^ ERROR unsatisfied lifetime constraints
46+
//~^ ERROR lifetime may not live long enough
4847
});
4948
}
5049

src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ note: External requirements
33
|
44
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
55
| _______________________________________________^
6-
LL | |
76
LL | | // Only works if 'x: 'y:
87
LL | | demand_y(x, y, x.get())
9-
LL | | //~^ ERROR unsatisfied lifetime constraints
8+
LL | | //~^ ERROR lifetime may not live long enough
109
LL | | });
1110
| |_____^
1211
|
@@ -24,17 +23,17 @@ note: No external requirements
2423
|
2524
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2625
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
27-
LL | |
2826
LL | | // Only works if 'x: 'y:
29-
... |
27+
LL | | demand_y(x, y, x.get())
28+
LL | | //~^ ERROR lifetime may not live long enough
3029
LL | | });
3130
LL | | }
3231
| |_^
3332
|
3433
= note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
3534

36-
error: unsatisfied lifetime constraints
37-
--> $DIR/propagate-approximated-ref.rs:46:9
35+
error: lifetime may not live long enough
36+
--> $DIR/propagate-approximated-ref.rs:45:9
3837
|
3938
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4039
| -- -- lifetime `'b` defined here

src/test/ui/nll/closure-requirements/propagate-approximated-val.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y:
3434
#[rustc_regions]
3535
fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
3636
establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
37-
3837
// Only works if 'x: 'y:
3938
demand_y(outlives1, outlives2, x.get())
40-
//~^ ERROR unsatisfied lifetime constraints
39+
//~^ ERROR lifetime may not live long enough
4140
});
4241
}
4342

src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ note: External requirements
33
|
44
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
55
| _____________________________________________^
6-
LL | |
76
LL | | // Only works if 'x: 'y:
87
LL | | demand_y(outlives1, outlives2, x.get())
9-
LL | | //~^ ERROR unsatisfied lifetime constraints
8+
LL | | //~^ ERROR lifetime may not live long enough
109
LL | | });
1110
| |_____^
1211
|
@@ -24,17 +23,17 @@ note: No external requirements
2423
|
2524
LL | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2625
LL | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
27-
LL | |
2826
LL | | // Only works if 'x: 'y:
29-
... |
27+
LL | | demand_y(outlives1, outlives2, x.get())
28+
LL | | //~^ ERROR lifetime may not live long enough
3029
LL | | });
3130
LL | | }
3231
| |_^
3332
|
3433
= note: defining type: DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]) with substs []
3534

36-
error: unsatisfied lifetime constraints
37-
--> $DIR/propagate-approximated-val.rs:39:9
35+
error: lifetime may not live long enough
36+
--> $DIR/propagate-approximated-val.rs:38:9
3837
|
3938
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4039
| -- -- lifetime `'b` defined here

src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | | });
1616
= note: late-bound region is '_#2r
1717
= note: late-bound region is '_#3r
1818

19-
error: unsatisfied lifetime constraints
19+
error: lifetime may not live long enough
2020
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:37:9
2121
|
2222
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {

src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | | });
1616
= note: late-bound region is '_#3r
1717
= note: late-bound region is '_#4r
1818

19-
error: unsatisfied lifetime constraints
19+
error: lifetime may not live long enough
2020
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:41:9
2121
|
2222
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {

src/test/ui/nll/closure-requirements/region-lbr-named-does-not-outlive-static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/region-lbr-named-does-not-outlive-static.rs:9:5
33
|
44
LL | fn foo<'a>(x: &'a u32) -> &'static u32 {

src/test/ui/nll/closure-requirements/region-lbr1-does-not-outlive-ebr2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

13-
fn main() { }
13+
fn main() {}

src/test/ui/nll/closure-requirements/region-lbr1-does-not-outlive-ebr2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/region-lbr1-does-not-outlive-ebr2.rs:9:5
33
|
44
LL | fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 {

src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | expect_sig(|a, b| b); // ought to return `a`
99
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
1010
]
1111

12-
error: unsatisfied lifetime constraints
12+
error: lifetime may not live long enough
1313
--> $DIR/return-wrong-bound-region.rs:11:23
1414
|
1515
LL | expect_sig(|a, b| b); // ought to return `a`

src/test/ui/nll/issue-48238.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/issue-48238.rs:11:13
33
|
44
LL | move || use_val(&orig); //~ ERROR

src/test/ui/nll/issue-50716.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/issue-50716.rs:16:14
33
|
44
LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)

src/test/ui/nll/issue-52113.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#![allow(warnings)]
44
#![feature(nll)]
55

6-
trait Bazinga { }
7-
impl<F> Bazinga for F { }
6+
trait Bazinga {}
7+
impl<F> Bazinga for F {}
88

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

24-
2524
fn produce3<'a, 'b: 'a>(data: &'a mut Vec<&'a u32>, value: &'b u32) -> impl Bazinga + 'a {
2625
let x = move || {
2726
let value: &'a u32 = value;
@@ -35,7 +34,7 @@ fn produce_err<'a, 'b: 'a>(data: &'b mut Vec<&'b u32>, value: &'a u32) -> impl B
3534
let value: &'a u32 = value;
3635
data.push(value);
3736
};
38-
x //~ ERROR unsatisfied lifetime constraints
37+
x //~ ERROR lifetime may not live long enough
3938
}
4039

41-
fn main() { }
40+
fn main() {}

src/test/ui/nll/issue-52113.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: unsatisfied lifetime constraints
2-
--> $DIR/issue-52113.rs:38:5
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-52113.rs:37:5
33
|
44
LL | fn produce_err<'a, 'b: 'a>(data: &'b mut Vec<&'b u32>, value: &'a u32) -> impl Bazinga + 'b {
55
| -- -- lifetime `'b` defined here
66
| |
77
| lifetime `'a` defined here
88
...
9-
LL | x //~ ERROR unsatisfied lifetime constraints
9+
LL | x //~ ERROR lifetime may not live long enough
1010
| ^ returning this value requires that `'a` must outlive `'b`
1111

1212
error: aborting due to previous error

src/test/ui/nll/issue-52742.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ struct Foo<'a, 'b> {
77
}
88

99
struct Bar<'b> {
10-
z: &'b u32
10+
z: &'b u32,
1111
}
1212

1313
impl Foo<'_, '_> {
1414
fn take_bar(&mut self, b: Bar<'_>) {
1515
self.y = b.z
16-
//~^ ERROR unsatisfied lifetime constraints
16+
//~^ ERROR lifetime may not live long enough
1717
}
1818
}
1919

20-
fn main() { }
20+
fn main() {}

src/test/ui/nll/issue-52742.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/issue-52742.rs:15:9
33
|
44
LL | fn take_bar(&mut self, b: Bar<'_>) {

src/test/ui/nll/issue-55394.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct Foo<'s> {
88

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

src/test/ui/nll/issue-55394.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/issue-55394.rs:11:9
33
|
44
LL | fn new(bar: &mut Bar) -> Self {
55
| - ---- return type is Foo<'2>
66
| |
77
| let's call the lifetime of this reference `'1`
8-
LL | Foo { bar } //~ ERROR unsatisfied lifetime constraints
8+
LL | Foo { bar } //~ERROR lifetime may not live long enough
99
| ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
1010

1111
error: aborting due to previous error

src/test/ui/nll/issue-55401.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/issue-55401.rs:5:5
33
|
44
LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 {

src/test/ui/nll/mir_check_cast_closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fn bar<'a, 'b>() -> fn(&'a u32, &'b u32) -> &'a u32 {
66
let g: fn(_, _) -> _ = |_x, y| y;
77
g
8-
//~^ ERROR unsatisfied lifetime constraints
8+
//~^ ERROR lifetime may not live long enough
99
}
1010

1111
fn main() {}

src/test/ui/nll/mir_check_cast_closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/mir_check_cast_closure.rs:7:5
33
|
44
LL | fn bar<'a, 'b>() -> fn(&'a u32, &'b u32) -> &'a u32 {

src/test/ui/nll/mir_check_cast_reify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn bar<'a>(x: &'a u32) -> &'static u32 {
3535
// as part of checking the `ReifyFnPointer`.
3636
let f: fn(_) -> _ = foo;
3737
f(x)
38-
//~^ ERROR unsatisfied lifetime constraints
38+
//~^ ERROR lifetime may not live long enough
3939
}
4040

4141
fn main() {}

src/test/ui/nll/mir_check_cast_reify.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/mir_check_cast_reify.rs:37:5
33
|
44
LL | fn bar<'a>(x: &'a u32) -> &'static u32 {

src/test/ui/nll/mir_check_cast_unsafe_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
77
// in `g`. These are related via the `UnsafeFnPointer` cast.
88
let g: unsafe fn(_) -> _ = f;
99
unsafe { g(input) }
10-
//~^ ERROR unsatisfied lifetime constraints
10+
//~^ ERROR lifetime may not live long enough
1111
}
1212

1313
fn main() {}

src/test/ui/nll/mir_check_cast_unsafe_fn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/mir_check_cast_unsafe_fn.rs:9:14
33
|
44
LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {

src/test/ui/nll/mir_check_cast_unsize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::Debug;
66

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

1212
fn main() {}

src/test/ui/nll/mir_check_cast_unsize.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unsatisfied lifetime constraints
1+
error: lifetime may not live long enough
22
--> $DIR/mir_check_cast_unsize.rs:8:5
33
|
44
LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug {

src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
4040
|
4141
= 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))`...
4242

43-
error: unsatisfied lifetime constraints
43+
error: lifetime may not live long enough
4444
--> $DIR/projection-one-region-closure.rs:45:39
4545
|
4646
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
@@ -94,7 +94,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
9494
|
9595
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
9696

97-
error: unsatisfied lifetime constraints
97+
error: lifetime may not live long enough
9898
--> $DIR/projection-one-region-closure.rs:56:39
9999
|
100100
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)

src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LL | | }
3131
T
3232
]
3333

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

79-
error: unsatisfied lifetime constraints
79+
error: lifetime may not live long enough
8080
--> $DIR/projection-one-region-trait-bound-closure.rs:47:39
8181
|
8282
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)

src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ where
8585
T: Anything<'b, 'b>,
8686
{
8787
with_signature(cell, t, |cell, t| require(cell, t));
88-
//~^ ERROR unsatisfied lifetime constraints
88+
//~^ ERROR lifetime may not live long enough
8989
}
9090

9191
#[rustc_regions]

0 commit comments

Comments
 (0)