Skip to content

Commit d1b35f9

Browse files
Improved named region errors
1 parent ef148cd commit d1b35f9

5 files changed

+38
-19
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
316316
let type_test_span = type_test.span;
317317

318318
if let Some(lower_bound_region) = lower_bound_region {
319-
let generic_ty = type_test.generic_kind.to_ty(self.infcx.tcx);
319+
let generic_ty = self.regioncx.name_regions(
320+
self.infcx.tcx,
321+
type_test.generic_kind.to_ty(self.infcx.tcx),
322+
);
320323
let origin = RelateParamBound(type_test_span, generic_ty, None);
321324
self.buffer_error(self.infcx.err_ctxt().construct_generic_bound_failure(
322325
self.body.source.def_id().expect_local(),
323326
type_test_span,
324327
Some(origin),
325-
type_test.generic_kind,
328+
self.regioncx.name_regions(self.infcx.tcx, type_test.generic_kind),
326329
lower_bound_region,
327330
));
328331
} else {

Diff for: tests/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr

+16-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ LL | | T: Anything<'b, 'c>,
2323
|
2424
= note: defining type: no_relationships_late::<'?1, '?2, T>
2525

26-
error[E0309]: the associated type `<T as Anything<'?5, '?6>>::AssocType` may not live long enough
26+
error[E0309]: the associated type `<T as Anything<'b/#0, 'c/#1>>::AssocType` may not live long enough
2727
--> $DIR/projection-two-region-trait-bound-closure.rs:38:39
2828
|
2929
LL | fn no_relationships_late<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
30-
| -- the associated type `<T as Anything<'?5, '?6>>::AssocType` must be valid for the lifetime `'a` as defined here...
30+
| -- the associated type `<T as Anything<'b/#0, 'c/#1>>::AssocType` must be valid for the lifetime `'a` as defined here...
3131
...
3232
LL | with_signature(cell, t, |cell, t| require(cell, t));
33-
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as Anything<'?5, '?6>>::AssocType` will meet its required lifetime bounds
33+
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as Anything<'b/#0, 'c/#1>>::AssocType` will meet its required lifetime bounds
34+
|
35+
help: consider adding an explicit lifetime bound
36+
|
37+
LL - T: Anything<'b, 'c>,
38+
LL + T: Anything<'b, 'c>, <T as Anything<'b/#0, 'c/#1>>::AssocType: 'a
3439
|
35-
= help: consider adding an explicit lifetime bound `<T as Anything<'?5, '?6>>::AssocType: 'a`...
3640

3741
note: external requirements
3842
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
@@ -59,16 +63,20 @@ LL | | 'a: 'a,
5963
|
6064
= note: defining type: no_relationships_early::<'?1, '?2, '?3, T>
6165

62-
error[E0309]: the associated type `<T as Anything<'?6, '?7>>::AssocType` may not live long enough
66+
error[E0309]: the associated type `<T as Anything<'b/#1, 'c/#2>>::AssocType` may not live long enough
6367
--> $DIR/projection-two-region-trait-bound-closure.rs:48:39
6468
|
6569
LL | fn no_relationships_early<'a, 'b, 'c, T>(cell: Cell<&'a ()>, t: T)
66-
| -- the associated type `<T as Anything<'?6, '?7>>::AssocType` must be valid for the lifetime `'a` as defined here...
70+
| -- the associated type `<T as Anything<'b/#1, 'c/#2>>::AssocType` must be valid for the lifetime `'a` as defined here...
6771
...
6872
LL | with_signature(cell, t, |cell, t| require(cell, t));
69-
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as Anything<'?6, '?7>>::AssocType` will meet its required lifetime bounds
73+
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as Anything<'b/#1, 'c/#2>>::AssocType` will meet its required lifetime bounds
74+
|
75+
help: consider adding an explicit lifetime bound
76+
|
77+
LL - 'a: 'a,
78+
LL + 'a: 'a, <T as Anything<'b/#1, 'c/#2>>::AssocType: 'a
7079
|
71-
= help: consider adding an explicit lifetime bound `<T as Anything<'?6, '?7>>::AssocType: 'a`...
7280

7381
note: external requirements
7482
--> $DIR/projection-two-region-trait-bound-closure.rs:61:29

Diff for: tests/ui/nll/ty-outlives/projection-where-clause-env-wrong-bound.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
error[E0309]: the associated type `<T as MyTrait<'_>>::Output` may not live long enough
1+
error[E0309]: the associated type `<T as MyTrait<'a>>::Output` may not live long enough
22
--> $DIR/projection-where-clause-env-wrong-bound.rs:15:5
33
|
44
LL | fn foo1<'a, 'b, T>() -> &'a ()
5-
| -- the associated type `<T as MyTrait<'_>>::Output` must be valid for the lifetime `'a` as defined here...
5+
| -- the associated type `<T as MyTrait<'a>>::Output` must be valid for the lifetime `'a` as defined here...
66
...
77
LL | bar::<T::Output>()
8-
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as MyTrait<'_>>::Output` will meet its required lifetime bounds
8+
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as MyTrait<'a>>::Output` will meet its required lifetime bounds
9+
|
10+
help: consider adding an explicit lifetime bound
11+
|
12+
LL - <T as MyTrait<'a>>::Output: 'b,
13+
LL + <T as MyTrait<'a>>::Output: 'b, <T as MyTrait<'a>>::Output: 'a
914
|
10-
= help: consider adding an explicit lifetime bound `<T as MyTrait<'_>>::Output: 'a`...
1115

1216
error: aborting due to 1 previous error
1317

Diff for: tests/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ where
1212
<T as MyTrait<'b>>::Output: 'a,
1313
{
1414
bar::<<T as MyTrait<'a>>::Output>()
15-
//~^ ERROR the associated type `<T as MyTrait<'_>>::Output` may not live long enough
15+
//~^ ERROR the associated type `<T as MyTrait<'a>>::Output` may not live long enough
1616
}
1717

1818
fn bar<'a, T>() -> &'a ()

Diff for: tests/ui/nll/ty-outlives/projection-where-clause-env-wrong-lifetime.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
error[E0309]: the associated type `<T as MyTrait<'_>>::Output` may not live long enough
1+
error[E0309]: the associated type `<T as MyTrait<'a>>::Output` may not live long enough
22
--> $DIR/projection-where-clause-env-wrong-lifetime.rs:14:5
33
|
44
LL | fn foo1<'a, 'b, T>() -> &'a ()
5-
| -- the associated type `<T as MyTrait<'_>>::Output` must be valid for the lifetime `'a` as defined here...
5+
| -- the associated type `<T as MyTrait<'a>>::Output` must be valid for the lifetime `'a` as defined here...
66
...
77
LL | bar::<<T as MyTrait<'a>>::Output>()
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `<T as MyTrait<'_>>::Output` will meet its required lifetime bounds
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `<T as MyTrait<'a>>::Output` will meet its required lifetime bounds
9+
|
10+
help: consider adding an explicit lifetime bound
11+
|
12+
LL - <T as MyTrait<'b>>::Output: 'a,
13+
LL + <T as MyTrait<'b>>::Output: 'a, <T as MyTrait<'a>>::Output: 'a
914
|
10-
= help: consider adding an explicit lifetime bound `<T as MyTrait<'_>>::Output: 'a`...
1115

1216
error: aborting due to 1 previous error
1317

0 commit comments

Comments
 (0)