Skip to content

Commit 2541c5b

Browse files
committed
Erase regions in default main E0277 message
1 parent 3ea12d4 commit 2541c5b

File tree

47 files changed

+83
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+83
-77
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,17 +2941,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
29412941
}
29422942
})
29432943
.unwrap_or_else(|| {
2944-
if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
2944+
let pred = self.tcx.erase_regions(if self.tcx.features().non_lifetime_binders {
2945+
// We can't erase the lifetime bounds on their own when this feature is enabled.
2946+
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
2947+
trait_predicate.skip_binder()
2948+
} else {
2949+
self.tcx.instantiate_bound_regions_with_erased(*trait_predicate)
2950+
});
2951+
if let ty::ImplPolarity::Positive = pred.polarity {
29452952
format!(
29462953
"the trait `{}` is not implemented for `{}`{post_message}",
2947-
trait_predicate.print_modifiers_and_trait_path(),
2948-
self.tcx
2949-
.short_ty_string(trait_predicate.skip_binder().self_ty(), &mut None),
2954+
pred.print_modifiers_and_trait_path(),
2955+
self.tcx.short_ty_string(pred.self_ty(), &mut None),
29502956
)
29512957
} else {
29522958
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
29532959
// not implemented for `T`".
2954-
format!("the trait bound `{trait_predicate}` is not satisfied{post_message}")
2960+
format!("the trait bound `{pred}` is not satisfied{post_message}")
29552961
}
29562962
})
29572963
}

tests/ui/associated-types/hr-associated-type-bound-object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ where
55
type U: ?Sized;
66
}
77
fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) {
8-
//~^ ERROR trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
8+
//~^ ERROR trait `Clone` is not implemented for `<T as X<'_>>::U`
99
<<T as X<'_>>::U>::clone(x);
10-
//~^ ERROR trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
11-
//~| ERROR trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
10+
//~^ ERROR trait `Clone` is not implemented for `<T as X<'_>>::U`
11+
//~| ERROR trait `Clone` is not implemented for `<T as X<'_>>::U`
1212
//~| ERROR trait `Clone` is not implemented for `<T as X<'_>>::U`
1313
}
1414

tests/ui/associated-types/hr-associated-type-bound-object.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
1+
error[E0277]: the trait `Clone` is not implemented for `<T as X<'_>>::U`
22
--> $DIR/hr-associated-type-bound-object.rs:7:13
33
|
44
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) {
@@ -17,7 +17,7 @@ help: consider further restricting the associated type
1717
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where for<'b> <T as X<'b>>::U: Clone {
1818
| ++++++++++++++++++++++++++++++++++++
1919

20-
error[E0277]: the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
20+
error[E0277]: the trait `Clone` is not implemented for `<T as X<'_>>::U`
2121
--> $DIR/hr-associated-type-bound-object.rs:9:7
2222
|
2323
LL | <<T as X<'_>>::U>::clone(x);
@@ -47,7 +47,7 @@ help: consider further restricting the associated type
4747
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where <T as X<'_>>::U: Clone {
4848
| ++++++++++++++++++++++++++++
4949

50-
error[E0277]: the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
50+
error[E0277]: the trait `Clone` is not implemented for `<T as X<'_>>::U`
5151
--> $DIR/hr-associated-type-bound-object.rs:9:5
5252
|
5353
LL | <<T as X<'_>>::U>::clone(x);

tests/ui/associated-types/hr-associated-type-bound-param-6.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ where
1010
}
1111

1212
impl<S, T> X<'_, T> for (S,) {
13-
//~^ ERROR trait `for<'b> X<'b, T>` is not implemented for `T`
13+
//~^ ERROR trait `X<'_, T>` is not implemented for `T`
1414
type U = str;
1515
}
1616

1717
pub fn main() {
1818
<(i32,) as X<i32>>::f("abc");
1919
//~^ ERROR trait `X<'_, i32>` is not implemented for `i32`
20-
//~| ERROR trait `for<'b> X<'b, i32>` is not implemented for `i32`
20+
//~| ERROR trait `X<'_, i32>` is not implemented for `i32`
2121
}

tests/ui/associated-types/hr-associated-type-bound-param-6.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait `for<'b> X<'b, T>` is not implemented for `T`
1+
error[E0277]: the trait `X<'_, T>` is not implemented for `T`
22
--> $DIR/hr-associated-type-bound-param-6.rs:12:12
33
|
44
LL | impl<S, T> X<'_, T> for (S,) {
@@ -9,7 +9,7 @@ help: consider restricting type parameter `T`
99
LL | impl<S, T: for<'b> X<'b, T>> X<'_, T> for (S,) {
1010
| ++++++++++++++++++
1111

12-
error[E0277]: the trait `for<'b> X<'b, i32>` is not implemented for `i32`
12+
error[E0277]: the trait `X<'_, i32>` is not implemented for `i32`
1313
--> $DIR/hr-associated-type-bound-param-6.rs:18:5
1414
|
1515
LL | <(i32,) as X<i32>>::f("abc");

tests/ui/associated-types/issue-43924.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
trait Foo<T: Default + ToString> {
77
type Out: Default + ToString + ?Sized = dyn ToString;
8-
//~^ ERROR the trait `Default` is not implemented for `(dyn ToString + 'static)`
8+
//~^ ERROR the trait `Default` is not implemented for `dyn ToString`
99
}
1010

1111
impl Foo<u32> for () {}

tests/ui/associated-types/issue-43924.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait `Default` is not implemented for `(dyn ToString + 'static)`
1+
error[E0277]: the trait `Default` is not implemented for `dyn ToString`
22
--> $DIR/issue-43924.rs:7:45
33
|
44
LL | type Out: Default + ToString + ?Sized = dyn ToString;

tests/ui/for/issue-20605.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
1+
error[E0277]: the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &mut u8>`
22
--> $DIR/issue-20605.rs:5:17
33
|
44
LL | for item in *things { *item = 0 }

tests/ui/for/issue-20605.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
55
for item in *things { *item = 0 }
66
//[current]~^ ERROR the size for values of type
7-
//[next]~^^ ERROR the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
7+
//[next]~^^ ERROR the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &mut u8>`
88
//[next]~| ERROR the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
99
//[next]~| ERROR the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
1010
//[next]~| ERROR the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed

tests/ui/generic-associated-types/issue-101020.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait Foo<T> {}
2929

3030
fn map_test() {
3131
(&mut EmptyIter).consume(());
32-
//~^ ERROR trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()`
32+
//~^ ERROR trait `Foo<&mut ()>` is not implemented for `&mut ()`
3333
}
3434

3535
fn main() {}

0 commit comments

Comments
 (0)