Skip to content

Commit a24e04d

Browse files
committed
say "the lifetime" instead of "some lifetime" when it feels right
In particular, when we want to indicate that there is a connection between the self type and the other types.
1 parent 7bc3f55 commit a24e04d

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
9595
ty::RePlaceholder(_),
9696
)) => {
9797
// I actually can't see why this would be the case ever.
98-
},
98+
}
9999

100100
Some(RegionResolutionError::ConcreteFailure(
101101
SubregionOrigin::Subtype(TypeTrace {
@@ -219,6 +219,10 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
219219
}
220220
});
221221

222+
let self_ty_has_vid = self
223+
.tcx
224+
.any_free_region_meets(&actual_trait_ref.self_ty(), |r| Some(r) == vid);
225+
222226
RegionHighlightMode::maybe_highlighting_region(sub_placeholder, has_sub, || {
223227
RegionHighlightMode::maybe_highlighting_region(sup_placeholder, has_sup, || {
224228
match (has_sub, has_sup) {
@@ -254,12 +258,21 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
254258

255259
RegionHighlightMode::maybe_highlighting_region(vid, has_vid, || match has_vid {
256260
Some(n) => {
257-
err.note(&format!(
258-
"but `{}` only implements `{}` for some lifetime `'{}`",
259-
actual_trait_ref.self_ty(),
260-
actual_trait_ref,
261-
n
262-
));
261+
if self_ty_has_vid {
262+
err.note(&format!(
263+
"but `{}` only implements `{}` for the lifetime `'{}`",
264+
actual_trait_ref.self_ty(),
265+
actual_trait_ref,
266+
n
267+
));
268+
} else {
269+
err.note(&format!(
270+
"but `{}` only implements `{}` for some lifetime `'{}`",
271+
actual_trait_ref.self_ty(),
272+
actual_trait_ref,
273+
n
274+
));
275+
}
263276
}
264277
None => {
265278
err.note(&format!(

src/test/ui/generator/auto-trait-regions.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | assert_foo(gen);
55
| ^^^^^^^^^^
66
|
77
= note: `&'0 OnlyFooIfStaticRef` must implement `Foo` for any lifetime `'0`
8-
= note: but `&'1 OnlyFooIfStaticRef` only implements `Foo` for some lifetime `'1`
8+
= note: but `&'1 OnlyFooIfStaticRef` only implements `Foo` for the lifetime `'1`
99

1010
error: implementation of `Foo` is not general enough
1111
--> $DIR/auto-trait-regions.rs:48:5
@@ -14,7 +14,7 @@ LL | assert_foo(gen);
1414
| ^^^^^^^^^^
1515
|
1616
= note: `A<'0, '1>` must implement `Foo` for any two lifetimes `'0` and `'1`
17-
= note: but `A<'_, '2>` only implements `Foo` for some lifetime `'2`
17+
= note: but `A<'_, '2>` only implements `Foo` for the lifetime `'2`
1818

1919
error: aborting due to 2 previous errors
2020

src/test/ui/hrtb/hrtb-just-for-static.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | want_hrtb::<&'a u32>() //~ ERROR
1616
|
1717
= note: Due to a where-clause on `want_hrtb`,
1818
= note: `&'a u32` must implement `Foo<&'0 isize>` for any lifetime `'0`
19-
= note: but `&'1 u32` only implements `Foo<&'1 isize>` for some lifetime `'1`
19+
= note: but `&'1 u32` only implements `Foo<&'1 isize>` for the lifetime `'1`
2020

2121
error: aborting due to 2 previous errors
2222

src/test/ui/issues/issue-54302-cases.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | <u32 as RefFoo<u32>>::ref_foo(a)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `&'0 u32` must implement `Foo<'static, u32>` for any lifetime `'0`
8-
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
8+
= note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1`
99

1010
error: implementation of `Foo` is not general enough
1111
--> $DIR/issue-54302-cases.rs:69:5
@@ -14,7 +14,7 @@ LL | <i32 as RefFoo<i32>>::ref_foo(a)
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= note: `&'0 i32` must implement `Foo<'static, i32>` for any lifetime `'0`
17-
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
17+
= note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1`
1818

1919
error: implementation of `Foo` is not general enough
2020
--> $DIR/issue-54302-cases.rs:75:5
@@ -23,7 +23,7 @@ LL | <u64 as RefFoo<u64>>::ref_foo(a)
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
|
2525
= note: `&'0 u64` must implement `Foo<'static, u64>` for any lifetime `'0`
26-
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
26+
= note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1`
2727

2828
error: implementation of `Foo` is not general enough
2929
--> $DIR/issue-54302-cases.rs:81:5
@@ -32,7 +32,7 @@ LL | <i64 as RefFoo<i64>>::ref_foo(a)
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333
|
3434
= note: `&'0 i64` must implement `Foo<'static, i64>` for any lifetime `'0`
35-
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
35+
= note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1`
3636

3737
error: aborting due to 4 previous errors
3838

src/test/ui/where-clauses/where-for-self-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | foo(&X); //~ ERROR implementation of `Bar` is not general enough
66
|
77
= note: Due to a where-clause on `foo`,
88
= note: `&'0 _` must implement `Bar` for any lifetime `'0`
9-
= note: but `&'1 u32` only implements `Bar` for some lifetime `'1`
9+
= note: but `&'1 u32` only implements `Bar` for the lifetime `'1`
1010

1111
error: aborting due to previous error
1212

0 commit comments

Comments
 (0)