Skip to content

Commit f80daf4

Browse files
committed
Erase lifetime in E0277 default label
1 parent 2541c5b commit f80daf4

File tree

74 files changed

+131
-124
lines changed

Some content is hidden

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

74 files changed

+131
-124
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,16 +4773,23 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
47734773
Some(desc) => format!(" {desc}"),
47744774
None => String::new(),
47754775
};
4776+
let pred = tcx.erase_regions(if tcx.features().non_lifetime_binders {
4777+
// We can't erase the lifetime bounds on their own when this feature is enabled.
4778+
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
4779+
trait_predicate.skip_binder()
4780+
} else {
4781+
tcx.instantiate_bound_regions_with_erased(*trait_predicate)
4782+
});
47764783
if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
47774784
format!(
47784785
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
4779-
trait_predicate.print_modifiers_and_trait_path(),
4780-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4786+
pred.print_modifiers_and_trait_path(),
4787+
tcx.short_ty_string(pred.self_ty(), &mut None),
47814788
)
47824789
} else {
47834790
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
47844791
// not implemented for `T`".
4785-
format!("{pre_message}the trait bound `{trait_predicate}` is not satisfied{post}")
4792+
format!("{pre_message}the trait bound `{pred}` is not satisfied{post}")
47864793
}
47874794
}
47884795
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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) {
5-
| ^^^^^ the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
5+
| ^^^^^ the trait `Clone` is not implemented for `<T as X<'_>>::U`
66
|
77
note: required by a bound in `X`
88
--> $DIR/hr-associated-type-bound-object.rs:3:33
@@ -21,7 +21,7 @@ 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);
24-
| ^ the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
24+
| ^ the trait `Clone` is not implemented for `<T as X<'_>>::U`
2525
|
2626
note: required by a bound in `X::U`
2727
--> $DIR/hr-associated-type-bound-object.rs:3:33
@@ -51,7 +51,7 @@ 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);
54-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<T as X<'_>>::U`
5555
|
5656
note: required by a bound in `X`
5757
--> $DIR/hr-associated-type-bound-object.rs:3:33

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
@@ -2,7 +2,7 @@ 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,) {
5-
| ^^^^^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
5+
| ^^^^^^^^ the trait `X<'_, T>` is not implemented for `T`
66
|
77
help: consider restricting type parameter `T`
88
|
@@ -13,7 +13,7 @@ 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");
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> X<'b, i32>` is not implemented for `i32`
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `X<'_, i32>` is not implemented for `i32`
1717
|
1818
= help: the trait `X<'_, T>` is implemented for `(S,)`
1919

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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;
5-
| ^^^^^^^^^^^^ the trait `Default` is not implemented for `(dyn ToString + 'static)`
5+
| ^^^^^^^^^^^^ the trait `Default` is not implemented for `dyn ToString`
66
|
77
note: required by a bound in `Foo::Out`
88
--> $DIR/issue-43924.rs:7:15

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _>
8484
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
8585
| ^^^^^^^ doesn't have a size known at compile-time
8686
|
87-
= help: the trait `Sized` is not implemented for `(dyn ThriftService<(), AssocType = _> + 'static)`
87+
= help: the trait `Sized` is not implemented for `dyn ThriftService<(), AssocType = _>`
8888
= help: unsized fn params are gated as an unstable feature
8989
help: you can use `impl Trait` as the argument type
9090
|

tests/ui/async-await/awaiting-unsized-param.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error[E0277]: the size for values of type `(dyn Future<Output = T> + Unpin + 'st
1313
LL | async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T {
1414
| ^^^^^ doesn't have a size known at compile-time
1515
|
16-
= help: the trait `Sized` is not implemented for `(dyn Future<Output = T> + Unpin + 'static)`
16+
= help: the trait `Sized` is not implemented for `dyn Future<Output = T> + Unpin`
1717
= note: all values captured by value by a closure must have a statically known size
1818

1919
error: aborting due to 1 previous error; 1 warning emitted

tests/ui/closures/capture-unsized-by-move.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let k2 = move || {
66
LL | k.to_string();
77
| ^ doesn't have a size known at compile-time
88
|
9-
= help: the trait `Sized` is not implemented for `(dyn std::fmt::Display + 'static)`
9+
= help: the trait `Sized` is not implemented for `dyn std::fmt::Display`
1010
= note: all values captured by value by a closure must have a statically known size
1111

1212
error: aborting due to 1 previous error

tests/ui/closures/issue-111932.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known
44
LL | foos.for_each(|foo| {
55
| ^^^ doesn't have a size known at compile-time
66
|
7-
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
7+
= help: the trait `Sized` is not implemented for `dyn Foo`
88
= note: all function arguments must have a statically known size
99
= help: unsized fn params are gated as an unstable feature
1010

tests/ui/consts/const-unsized.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot
44
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
55
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
66
|
7-
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
7+
= help: the trait `Sized` is not implemented for `dyn Debug + Sync`
88

99
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
1010
--> $DIR/const-unsized.rs:3:35
1111
|
1212
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
1414
|
15-
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
15+
= help: the trait `Sized` is not implemented for `dyn Debug + Sync`
1616
= note: constant expressions must have a statically known size
1717

1818
error[E0277]: the size for values of type `str` cannot be known at compilation time
@@ -38,15 +38,15 @@ error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot
3838
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
3939
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
4040
|
41-
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
41+
= help: the trait `Sized` is not implemented for `dyn Debug + Sync`
4242

4343
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
4444
--> $DIR/const-unsized.rs:11:37
4545
|
4646
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
4848
|
49-
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
49+
= help: the trait `Sized` is not implemented for `dyn Debug + Sync`
5050
= note: constant expressions must have a statically known size
5151

5252
error[E0277]: the size for values of type `str` cannot be known at compilation time

tests/ui/expr/malformed_closure/block_instead_of_closure_in_arg.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | || }
1414
LL | | });
1515
| |______^ expected an `FnOnce(&bool)` closure, found `bool`
1616
|
17-
= help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool`
17+
= help: the trait `FnOnce<(&bool,)>` is not implemented for `bool`
1818
note: required by a bound in `Option::<T>::filter`
1919
--> $SRC_DIR/core/src/option.rs:LL:COL
2020
help: you might have meant to create the closure instead of a block

0 commit comments

Comments
 (0)