Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword E0277 default error message #121766

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4773,11 +4773,24 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
Some(desc) => format!(" {desc}"),
None => String::new(),
};
format!(
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
trait_predicate.print_modifiers_and_trait_path(),
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
)
let pred = tcx.erase_regions(if tcx.features().non_lifetime_binders {
// We can't erase the lifetime bounds on their own when this feature is enabled.
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
trait_predicate.skip_binder()
} else {
tcx.instantiate_bound_regions_with_erased(*trait_predicate)
});
if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
format!(
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
pred.print_modifiers_and_trait_path(),
tcx.short_ty_string(pred.self_ty(), &mut None),
)
} else {
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
// not implemented for `T`".
format!("{pre_message}the trait bound `{pred}` is not satisfied{post}")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
})
.unwrap_or_else(|| {
format!("the trait bound `{trait_predicate}` is not satisfied{post_message}")
let pred = self.tcx.erase_regions(if self.tcx.features().non_lifetime_binders {
// We can't erase the lifetime bounds on their own when this feature is enabled.
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
trait_predicate.skip_binder()
} else {
self.tcx.instantiate_bound_regions_with_erased(*trait_predicate)
});
if let ty::ImplPolarity::Positive = pred.polarity {
format!(
"the trait `{}` is not implemented for `{}`{post_message}",
pred.print_modifiers_and_trait_path(),
self.tcx.short_ty_string(pred.self_ty(), &mut None),
)
} else {
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
// not implemented for `T`".
format!("the trait bound `{pred}` is not satisfied{post_message}")
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions tests/incremental/const-generics/hash-tyvid-regression-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ where
{
use std::convert::TryFrom;
<[T; N.get()]>::try_from(())
//~^ error: the trait bound
//~| error: the trait bound
//~^ ERROR the trait `From<()>` is not implemented for `[T; N.get()]`
//~| ERROR the trait `From<()>` is not implemented for `[T; N.get()]`
//~| error: mismatched types
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ where
C: Delegates<FileCap<{ false }>>,
{
writes_to_specific_path(&cap);
//~^ error: the trait bound
//~^ ERROR the trait `Delegates<FileCap<false>>` is not implemented for `&C`
}

fn writes_to_specific_path<C>(cap: &C)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ where
[(); { S * 2 }]: Default;

impl<'a, T, const S: usize> Iterator for BufferIter<'a, T, S> {
//~^ error: the trait bound
//~^^ error: unconstrained generic constant
//~^ ERROR the trait `Default` is not implemented for `[(); { S * 2 }]`
//~| ERROR unconstrained generic constant
type Item = &'a T;

fn next(&mut self) -> Option<Self::Item> {
//~^ error: the trait bound
//~^^ error: unconstrained generic constant
//~^ ERROR the trait `Default` is not implemented for `[(); { S * 2 }]`
//~| ERROR unconstrained generic constant
None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Test {
span: Span,
/// A doc comment
arg: NotIntoDiagnosticArg,
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
}

#[derive(Subdiagnostic)]
Expand All @@ -44,5 +44,5 @@ struct SubTest {
span: Span,
/// A doc comment
arg: NotIntoDiagnosticArg,
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
--> $DIR/diagnostic-derive-doc-comment-field.rs:36:10
|
LL | #[derive(Diagnostic)]
Expand All @@ -12,7 +12,7 @@ note: required by a bound in `Diag::<'a, G>::arg`
--> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC
= note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
--> $DIR/diagnostic-derive-doc-comment-field.rs:46:10
|
LL | #[derive(Subdiagnostic)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ struct ArgFieldWithoutSkip {
#[primary_span]
span: Span,
other: Hello,
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `Hello`
}

#[derive(Diagnostic)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ LL | #[derive(Diagnostic)]
|
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `Hello`
--> $DIR/diagnostic-derive.rs:349:12
|
LL | #[derive(Diagnostic)]
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/allocator/not-an-allocator.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
--> $DIR/not-an-allocator.rs:2:11
|
LL | #[global_allocator]
Expand All @@ -9,7 +9,7 @@ LL | static A: usize = 0;
= help: the trait `GlobalAlloc` is implemented for `System`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
--> $DIR/not-an-allocator.rs:2:11
|
LL | #[global_allocator]
Expand All @@ -21,7 +21,7 @@ LL | static A: usize = 0;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
--> $DIR/not-an-allocator.rs:2:11
|
LL | #[global_allocator]
Expand All @@ -33,7 +33,7 @@ LL | static A: usize = 0;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
--> $DIR/not-an-allocator.rs:2:11
|
LL | #[global_allocator]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/array-slice-vec/repeat_empty_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub struct Header<'a> {

pub fn test() {
let headers = [Header{value: &[]}; 128];
//~^ ERROR the trait bound
//~^ ERROR the trait
}

pub fn test2() {
let headers = [Header{value: &[0]}; 128];
//~^ ERROR the trait bound
//~^ ERROR the trait
}
4 changes: 2 additions & 2 deletions tests/ui/array-slice-vec/repeat_empty_ok.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `Header<'_>`
--> $DIR/repeat_empty_ok.rs:8:20
|
LL | let headers = [Header{value: &[]}; 128];
Expand All @@ -13,7 +13,7 @@ LL + #[derive(Copy)]
LL | pub struct Header<'a> {
|

error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `Header<'_>`
--> $DIR/repeat_empty_ok.rs:13:20
|
LL | let headers = [Header{value: &[0]}; 128];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-consts/associated-const-array-len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ trait Foo {
}

const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
//~^ ERROR the trait bound `i32: Foo` is not satisfied
//~^ ERROR trait `Foo` is not implemented for `i32`

fn main() {
assert_eq!(1, X);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `i32: Foo` is not satisfied
error[E0277]: the trait `Foo` is not implemented for `i32`
--> $DIR/associated-const-array-len.rs:5:17
|
LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-consts/issue-105330.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl TraitWAssocConst for impl Demo { //~ ERROR E0404

fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
foo::<Demo>()();
//~^ ERROR is not satisfied
//~^ ERROR is not implemented
//~| ERROR type mismatch
//~| ERROR expected function, found `()`
}
Expand All @@ -20,5 +20,5 @@ fn main<A: TraitWAssocConst<A=32>>() {
//~| ERROR E0131
foo::<Demo>();
//~^ ERROR type mismatch
//~| ERROR is not satisfied
//~| ERROR is not implemented
}
4 changes: 2 additions & 2 deletions tests/ui/associated-consts/issue-105330.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ error[E0131]: `main` function is not allowed to have generic parameters
LL | fn main<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters

error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
--> $DIR/issue-105330.rs:12:11
|
LL | foo::<Demo>()();
Expand Down Expand Up @@ -86,7 +86,7 @@ LL | foo::<Demo>()();
| |
| call expression requires function

error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
error[E0277]: the trait `TraitWAssocConst` is not implemented for `Demo`
--> $DIR/issue-105330.rs:21:11
|
LL | foo::<Demo>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `String`
--> $DIR/generic-associated-types-bad.rs:16:10
|
LL | const _: Ty::Pr<String> = String::new();
Expand All @@ -10,7 +10,7 @@ note: required by a bound in `Ty::Pr`
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

error[E0277]: the trait bound `String: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `String`
--> $DIR/generic-associated-types-bad.rs:16:27
|
LL | const _: Ty::Pr<String> = String::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `Vec<()>: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `Vec<()>`
--> $DIR/generic-associated-types-bad.rs:21:12
|
LL | let _: Ty::Pr<Vec<()>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ impl Ty {
}

#[cfg(item)]
const _: Ty::Pr<String> = String::new(); //[item]~ the trait bound `String: Copy` is not satisfied
//[item]~^ the trait bound `String: Copy` is not satisfied
const _: Ty::Pr<String> = String::new(); //[item]~ ERROR trait `Copy` is not implemented for `String`
//[item]~^ ERROR trait `Copy` is not implemented for `String`

fn main() {
#[cfg(local)]
let _: Ty::Pr<Vec<()>>; //[local]~ ERROR the trait bound `Vec<()>: Copy` is not satisfied
let _: Ty::Pr<Vec<()>>; //[local]~ ERROR trait `Copy` is not implemented for `Vec<()>`
}

fn user<'a>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ impl<T: Copy> S<T> {
}

fn main() {
let _: S<_>::T = String::new(); //~ ERROR the trait bound `String: Copy` is not satisfied
let _: S<_>::T = String::new(); //~ ERROR trait `Copy` is not implemented for `String`
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `String`
--> $DIR/unsatisfied-bounds-inferred-type.rs:11:12
|
LL | let _: S<_>::T = String::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ impl<T> S<T> {
}

fn main() {
let _: S::<String>::X; //~ ERROR the trait bound `String: Copy` is not satisfied
let _: S::<String>::X; //~ ERROR trait `Copy` is not implemented for `String`
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
error[E0277]: the trait `Copy` is not implemented for `String`
--> $DIR/unsatisfied-bounds-where-clause-on-assoc-ty.rs:13:12
|
LL | let _: S::<String>::X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ trait Add<RHS=Self> {
fn ice<A>(a: A) {
let r = loop {};
r = r + a;
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
//~^ ERROR trait `Add<A>` is not implemented for `()`
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `(): Add<A>` is not satisfied
error[E0277]: the trait `Add<A>` is not implemented for `()`
--> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:23:11
|
LL | r = r + a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `<G as GetToInt>::R: ToInt` is not satisfied
error[E0277]: the trait `ToInt` is not implemented for `<G as GetToInt>::R`
--> $DIR/associated-types-bound-failure.rs:19:19
|
LL | ToInt::to_int(&g.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ trait Get {

trait Other {
fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get, Self: Get {}
//~^ ERROR the trait bound `Self: Get` is not satisfied
//~| ERROR the trait bound `Self: Get` is not satisfied
//~^ ERROR trait `Get` is not implemented for `Self`
//~| ERROR trait `Get` is not implemented for `Self`
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ trait Get {

trait Other {
fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
//~^ ERROR the trait bound `Self: Get` is not satisfied
//~| ERROR the trait bound `Self: Get` is not satisfied
//~^ ERROR trait `Get` is not implemented for `Self`
//~| ERROR trait `Get` is not implemented for `Self`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `Self: Get` is not satisfied
error[E0277]: the trait `Get` is not implemented for `Self`
--> $DIR/associated-types-for-unimpl-trait.rs:11:41
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
Expand All @@ -9,7 +9,7 @@ help: consider further restricting `Self`
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
| +++++++++++

error[E0277]: the trait bound `Self: Get` is not satisfied
error[E0277]: the trait `Get` is not implemented for `Self`
--> $DIR/associated-types-for-unimpl-trait.rs:11:81
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait Foo<T> {

fn f<T:Foo<isize>>(t: &T) {
let u: <T as Foo<usize>>::Bar = t.get_bar();
//~^ ERROR the trait bound `T: Foo<usize>` is not satisfied
//~^ ERROR trait `Foo<usize>` is not implemented for `T`
}

fn main() { }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `T: Foo<usize>` is not satisfied
error[E0277]: the trait `Foo<usize>` is not implemented for `T`
--> $DIR/associated-types-invalid-trait-ref-issue-18865.rs:10:13
|
LL | let u: <T as Foo<usize>>::Bar = t.get_bar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct Struct {

impl Struct {
fn uhoh<T>(foo: <T as Get>::Value) {}
//~^ ERROR the trait bound `T: Get` is not satisfied
//~| ERROR the trait bound `T: Get` is not satisfied
//~^ ERROR trait `Get` is not implemented for `T`
//~| ERROR trait `Get` is not implemented for `T`
}

fn main() {}
Loading
Loading