Skip to content

Commit 3819180

Browse files
Improved named region errors
1 parent f2c4ccd commit 3819180

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
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

+14-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ 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
3434
|
35-
= help: consider adding an explicit lifetime bound `<T as Anything<'?5, '?6>>::AssocType: 'a`...
35+
help: consider adding an explicit lifetime bound
36+
|
37+
LL | T: Anything<'b, 'c>, <T as Anything<'b/#0, 'c/#1>>::AssocType: 'a
38+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3639

3740
note: external requirements
3841
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
@@ -59,16 +62,19 @@ LL | | 'a: 'a,
5962
|
6063
= note: defining type: no_relationships_early::<'?1, '?2, '?3, T>
6164

62-
error[E0309]: the associated type `<T as Anything<'?6, '?7>>::AssocType` may not live long enough
65+
error[E0309]: the associated type `<T as Anything<'b/#1, 'c/#2>>::AssocType` may not live long enough
6366
--> $DIR/projection-two-region-trait-bound-closure.rs:48:39
6467
|
6568
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...
69+
| -- the associated type `<T as Anything<'b/#1, 'c/#2>>::AssocType` must be valid for the lifetime `'a` as defined here...
6770
...
6871
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
72+
| ^^^^^^^^^^^^^^^^ ...so that the type `<T as Anything<'b/#1, 'c/#2>>::AssocType` will meet its required lifetime bounds
73+
|
74+
help: consider adding an explicit lifetime bound
7075
|
71-
= help: consider adding an explicit lifetime bound `<T as Anything<'?6, '?7>>::AssocType: 'a`...
76+
LL | 'a: 'a, <T as Anything<'b/#1, 'c/#2>>::AssocType: 'a
77+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7278

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

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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
99
|
10-
= help: consider adding an explicit lifetime bound `<T as MyTrait<'_>>::Output: 'a`...
10+
help: consider adding an explicit lifetime bound
11+
|
12+
LL | <T as MyTrait<'a>>::Output: 'b, <T as MyTrait<'a>>::Output: 'a
13+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1114

1215
error: aborting due to 1 previous error
1316

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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
99
|
10-
= help: consider adding an explicit lifetime bound `<T as MyTrait<'_>>::Output: 'a`...
10+
help: consider adding an explicit lifetime bound
11+
|
12+
LL | <T as MyTrait<'b>>::Output: 'a, <T as MyTrait<'a>>::Output: 'a
13+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1114

1215
error: aborting due to 1 previous error
1316

0 commit comments

Comments
 (0)