Skip to content

Commit 03bcebb

Browse files
committed
Also point to free named region on lifetime errors
1 parent 3005162 commit 03bcebb

11 files changed

+45
-52
lines changed

src/librustc/infer/error_reporting/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
232232
}
233233
(format!("the lifetime {} as defined on", br.name), sp)
234234
}
235+
ty::ReFree(ty::FreeRegion {
236+
bound_region: ty::BoundRegion::BrNamed(_, ref name), ..
237+
}) => {
238+
let mut sp = cm.def_span(self.hir.span(node));
239+
if let Some(generics) = self.hir.get_generics(scope) {
240+
for param in &generics.params {
241+
if param.name.name().as_str() == name.as_str() {
242+
sp = param.span;
243+
}
244+
}
245+
}
246+
(format!("the lifetime {} as defined on", name), sp)
247+
}
235248
ty::ReFree(ref fr) => match fr.bound_region {
236249
ty::BrAnon(idx) => (
237250
format!("the anonymous lifetime #{} defined on", idx + 1),

src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | //~^ ERROR E0373
77
LL | }
88
| - borrowed value only lives until here
99
|
10-
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:1...
11-
--> $DIR/borrowck-escaping-closure-error-2.rs:19:1
10+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:8...
11+
--> $DIR/borrowck-escaping-closure-error-2.rs:19:8
1212
|
1313
LL | fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ^^
1515

1616
error: aborting due to previous error
1717

src/test/ui/borrowck/regions-bound-missing-bound-in-impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl<'a, 't> Foo<'a, 't> for &'a isize {
3636

3737
fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
3838
//~^ ERROR method not compatible with trait
39-
//~| ERROR method not compatible with trait
4039
//
4140
// Note: This is a terrible error message. It is caused
4241
// because, in the trait, 'b is early bound, and in the impl,

src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

+5-24
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,19 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
2424
|
2525
= note: expected type `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'d>)`
2626
found type `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'d>)`
27-
note: the lifetime 'c as defined on the method body at 37:5...
28-
--> $DIR/regions-bound-missing-bound-in-impl.rs:37:5
29-
|
30-
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32-
note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 37:24
27+
note: the lifetime 'c as defined on the method body at 37:24...
3328
--> $DIR/regions-bound-missing-bound-in-impl.rs:37:24
3429
|
3530
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
3631
| ^^
37-
38-
error[E0308]: method not compatible with trait
39-
--> $DIR/regions-bound-missing-bound-in-impl.rs:37:5
40-
|
41-
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
42-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
43-
|
44-
= note: expected type `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'d>)`
45-
found type `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'d>)`
46-
note: the lifetime 'c as defined on the method body at 37:24...
32+
note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 37:24
4733
--> $DIR/regions-bound-missing-bound-in-impl.rs:37:24
4834
|
4935
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
5036
| ^^
51-
note: ...does not necessarily outlive the lifetime 'c as defined on the method body at 37:5
52-
--> $DIR/regions-bound-missing-bound-in-impl.rs:37:5
53-
|
54-
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5637

5738
error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration
58-
--> $DIR/regions-bound-missing-bound-in-impl.rs:52:5
39+
--> $DIR/regions-bound-missing-bound-in-impl.rs:51:5
5940
|
6041
LL | fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
6142
| ---------------- lifetimes in impl do not match this method in trait
@@ -64,15 +45,15 @@ LL | fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) {
6445
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait
6546

6647
error[E0276]: impl has stricter requirements than trait
67-
--> $DIR/regions-bound-missing-bound-in-impl.rs:59:5
48+
--> $DIR/regions-bound-missing-bound-in-impl.rs:58:5
6849
|
6950
LL | fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
7051
| ------------------------------------------------------- definition of `another_bound` from trait
7152
...
7253
LL | fn another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) {
7354
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'x: 't`
7455

75-
error: aborting due to 6 previous errors
56+
error: aborting due to 5 previous errors
7657

7758
Some errors occurred: E0195, E0276, E0308.
7859
For more information about an error, try `rustc --explain E0195`.

src/test/ui/closure-expected-type/expect-region-supply-region.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ LL | |
3838
LL | | //~^ ERROR borrowed data cannot be stored outside of its closure
3939
LL | | });
4040
| |_____^
41-
note: ...does not necessarily outlive the lifetime 'x as defined on the function body at 42:1
42-
--> $DIR/expect-region-supply-region.rs:42:1
41+
note: ...does not necessarily outlive the lifetime 'x as defined on the function body at 42:30
42+
--> $DIR/expect-region-supply-region.rs:42:30
4343
|
4444
LL | fn expect_bound_supply_named<'x>() {
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
| ^^
4646

4747
error[E0308]: mismatched types
4848
--> $DIR/expect-region-supply-region.rs:47:33
@@ -52,11 +52,11 @@ LL | closure_expecting_bound(|x: &'x u32| {
5252
|
5353
= note: expected type `&u32`
5454
found type `&'x u32`
55-
note: the lifetime 'x as defined on the function body at 42:1...
56-
--> $DIR/expect-region-supply-region.rs:42:1
55+
note: the lifetime 'x as defined on the function body at 42:30...
56+
--> $DIR/expect-region-supply-region.rs:42:30
5757
|
5858
LL | fn expect_bound_supply_named<'x>() {
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59+
| ^^
6060
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 47:29
6161
--> $DIR/expect-region-supply-region.rs:47:29
6262
|

src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen
44
LL | static_val(x); //~ ERROR cannot infer
55
| ^
66
|
7-
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:1...
8-
--> $DIR/dyn-trait.rs:31:1
7+
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:26...
8+
--> $DIR/dyn-trait.rs:31:26
99
|
1010
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^
1212
= note: ...so that the expression is assignable:
1313
expected std::boxed::Box<dyn std::fmt::Debug>
1414
found std::boxed::Box<(dyn std::fmt::Debug + 'a)>

src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ LL | / fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR cannot infe
1111
LL | | x
1212
LL | | }
1313
| |_____^
14-
note: ...but the lifetime must also be valid for the lifetime 'a as defined on the method body at 19:5...
15-
--> $DIR/mismatched_trait_impl.rs:19:5
14+
note: ...but the lifetime must also be valid for the lifetime 'a as defined on the method body at 19:32...
15+
--> $DIR/mismatched_trait_impl.rs:19:32
1616
|
1717
LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR cannot infer
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
| ^^
1919
= note: ...so that the method type is compatible with trait:
2020
expected fn(&i32, &'a u32, &u32) -> &'a u32
2121
found fn(&i32, &u32, &u32) -> &u32

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ LL | id(Box::new(|| *v))
1313
LL | }
1414
| - borrowed value only lives until here
1515
|
16-
note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:1...
17-
--> $DIR/issue-4335.rs:15:1
16+
note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:6...
17+
--> $DIR/issue-4335.rs:15:6
1818
|
1919
LL | fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| ^^
2121

2222
error: aborting due to 2 previous errors
2323

src/test/ui/nll/borrowed-universal-error-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | //~^ ERROR `v` does not live long enough [E0597]
77
LL | }
88
| - borrowed value only lives until here
99
|
10-
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:1...
11-
--> $DIR/borrowed-universal-error-2.rs:14:1
10+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
11+
--> $DIR/borrowed-universal-error-2.rs:14:8
1212
|
1313
LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ^^
1515

1616
error: aborting due to previous error
1717

src/test/ui/nll/borrowed-universal-error.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | //~^ ERROR borrowed value does not live long enough [E0597]
77
LL | }
88
| - temporary value only lives until here
99
|
10-
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:1...
11-
--> $DIR/borrowed-universal-error.rs:18:1
10+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:8...
11+
--> $DIR/borrowed-universal-error.rs:18:8
1212
|
1313
LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ^^
1515

1616
error: aborting due to previous error
1717

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | &s_inner.0
77
LL | }
88
| - borrowed value only lives until here
99
|
10-
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:1...
11-
--> $DIR/issue-31567.rs:21:1
10+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:17...
11+
--> $DIR/issue-31567.rs:21:17
1212
|
1313
LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ^^
1515

1616
error: aborting due to previous error
1717

0 commit comments

Comments
 (0)