From a24e04dff6b9b92bbec791c61a69876401d10512 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 18 Nov 2018 19:13:37 -0500 Subject: [PATCH] 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. --- .../nice_region_error/placeholder_error.rs | 27 ++++++++++++++----- .../ui/generator/auto-trait-regions.stderr | 4 +-- src/test/ui/hrtb/hrtb-just-for-static.stderr | 2 +- src/test/ui/issues/issue-54302-cases.stderr | 8 +++--- .../ui/where-clauses/where-for-self-2.stderr | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 4e59c8c43dc..07a61eb6d77 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -95,7 +95,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { ty::RePlaceholder(_), )) => { // I actually can't see why this would be the case ever. - }, + } Some(RegionResolutionError::ConcreteFailure( SubregionOrigin::Subtype(TypeTrace { @@ -219,6 +219,10 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { } }); + let self_ty_has_vid = self + .tcx + .any_free_region_meets(&actual_trait_ref.self_ty(), |r| Some(r) == vid); + RegionHighlightMode::maybe_highlighting_region(sub_placeholder, has_sub, || { RegionHighlightMode::maybe_highlighting_region(sup_placeholder, has_sup, || { match (has_sub, has_sup) { @@ -254,12 +258,21 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { RegionHighlightMode::maybe_highlighting_region(vid, has_vid, || match has_vid { Some(n) => { - err.note(&format!( - "but `{}` only implements `{}` for some lifetime `'{}`", - actual_trait_ref.self_ty(), - actual_trait_ref, - n - )); + if self_ty_has_vid { + err.note(&format!( + "but `{}` only implements `{}` for the lifetime `'{}`", + actual_trait_ref.self_ty(), + actual_trait_ref, + n + )); + } else { + err.note(&format!( + "but `{}` only implements `{}` for some lifetime `'{}`", + actual_trait_ref.self_ty(), + actual_trait_ref, + n + )); + } } None => { err.note(&format!( diff --git a/src/test/ui/generator/auto-trait-regions.stderr b/src/test/ui/generator/auto-trait-regions.stderr index 94162cb9e8f..1b4dfe2df1c 100644 --- a/src/test/ui/generator/auto-trait-regions.stderr +++ b/src/test/ui/generator/auto-trait-regions.stderr @@ -5,7 +5,7 @@ LL | assert_foo(gen); | ^^^^^^^^^^ | = note: `&'0 OnlyFooIfStaticRef` must implement `Foo` for any lifetime `'0` - = note: but `&'1 OnlyFooIfStaticRef` only implements `Foo` for some lifetime `'1` + = note: but `&'1 OnlyFooIfStaticRef` only implements `Foo` for the lifetime `'1` error: implementation of `Foo` is not general enough --> $DIR/auto-trait-regions.rs:48:5 @@ -14,7 +14,7 @@ LL | assert_foo(gen); | ^^^^^^^^^^ | = note: `A<'0, '1>` must implement `Foo` for any two lifetimes `'0` and `'1` - = note: but `A<'_, '2>` only implements `Foo` for some lifetime `'2` + = note: but `A<'_, '2>` only implements `Foo` for the lifetime `'2` error: aborting due to 2 previous errors diff --git a/src/test/ui/hrtb/hrtb-just-for-static.stderr b/src/test/ui/hrtb/hrtb-just-for-static.stderr index ee518b956ab..094c4498024 100644 --- a/src/test/ui/hrtb/hrtb-just-for-static.stderr +++ b/src/test/ui/hrtb/hrtb-just-for-static.stderr @@ -16,7 +16,7 @@ LL | want_hrtb::<&'a u32>() //~ ERROR | = note: Due to a where-clause on `want_hrtb`, = note: `&'a u32` must implement `Foo<&'0 isize>` for any lifetime `'0` - = note: but `&'1 u32` only implements `Foo<&'1 isize>` for some lifetime `'1` + = note: but `&'1 u32` only implements `Foo<&'1 isize>` for the lifetime `'1` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-54302-cases.stderr b/src/test/ui/issues/issue-54302-cases.stderr index 6469829e789..c1329d331a1 100644 --- a/src/test/ui/issues/issue-54302-cases.stderr +++ b/src/test/ui/issues/issue-54302-cases.stderr @@ -5,7 +5,7 @@ LL | >::ref_foo(a) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `&'0 u32` must implement `Foo<'static, u32>` for any lifetime `'0` - = note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1` + = note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1` error: implementation of `Foo` is not general enough --> $DIR/issue-54302-cases.rs:69:5 @@ -14,7 +14,7 @@ LL | >::ref_foo(a) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `&'0 i32` must implement `Foo<'static, i32>` for any lifetime `'0` - = note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1` + = note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1` error: implementation of `Foo` is not general enough --> $DIR/issue-54302-cases.rs:75:5 @@ -23,7 +23,7 @@ LL | >::ref_foo(a) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `&'0 u64` must implement `Foo<'static, u64>` for any lifetime `'0` - = note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1` + = note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1` error: implementation of `Foo` is not general enough --> $DIR/issue-54302-cases.rs:81:5 @@ -32,7 +32,7 @@ LL | >::ref_foo(a) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `&'0 i64` must implement `Foo<'static, i64>` for any lifetime `'0` - = note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1` + = note: but `&'1 _` only implements `Foo<'_, _>` for the lifetime `'1` error: aborting due to 4 previous errors diff --git a/src/test/ui/where-clauses/where-for-self-2.stderr b/src/test/ui/where-clauses/where-for-self-2.stderr index 06f3659a5c1..afc80bf4d8e 100644 --- a/src/test/ui/where-clauses/where-for-self-2.stderr +++ b/src/test/ui/where-clauses/where-for-self-2.stderr @@ -6,7 +6,7 @@ LL | foo(&X); //~ ERROR implementation of `Bar` is not general enough | = note: Due to a where-clause on `foo`, = note: `&'0 _` must implement `Bar` for any lifetime `'0` - = note: but `&'1 u32` only implements `Bar` for some lifetime `'1` + = note: but `&'1 u32` only implements `Bar` for the lifetime `'1` error: aborting due to previous error