Skip to content

Commit ebbd167

Browse files
committed
Reword E0277 default error message
``` error[E0277]: the trait `Copy` is not implemented for `X` --> $DIR/trait-impl-bound-suggestions.rs:14:52 | LL | fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> { | ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `X` ```
1 parent c475e23 commit ebbd167

File tree

739 files changed

+1428
-1402
lines changed

Some content is hidden

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

739 files changed

+1428
-1402
lines changed

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,20 +4769,28 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
47694769
} else {
47704770
String::new()
47714771
};
4772-
match ty_desc {
4773-
Some(desc) => format!(
4774-
"{}the trait `{}` is not implemented for {} `{}`{post}",
4775-
pre_message,
4776-
trait_predicate.print_modifiers_and_trait_path(),
4777-
desc,
4778-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4779-
),
4780-
None => format!(
4781-
"{}the trait `{}` is not implemented for `{}`{post}",
4782-
pre_message,
4783-
trait_predicate.print_modifiers_and_trait_path(),
4784-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4785-
),
4772+
let desc = match ty_desc {
4773+
Some(desc) => format!(" {desc}"),
4774+
None => String::new(),
4775+
};
4776+
4777+
let pred = tcx.erase_regions(if tcx.features().non_lifetime_binders {
4778+
// We can't erase the lifetime bounds on their own when this feature is enabled.
4779+
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
4780+
trait_predicate.skip_binder()
4781+
} else {
4782+
tcx.instantiate_bound_regions_with_erased(*trait_predicate)
4783+
});
4784+
if let ty::ImplPolarity::Positive = pred.polarity {
4785+
format!(
4786+
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
4787+
pred.print_modifiers_and_trait_path(),
4788+
tcx.short_ty_string(pred.self_ty(), &mut None),
4789+
)
4790+
} else {
4791+
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
4792+
// not implemented for `T`".
4793+
format!("{pre_message}the trait bound `{pred}` is not satisfied{post}")
47864794
}
47874795
}
47884796
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
29412941
}
29422942
})
29432943
.unwrap_or_else(|| {
2944-
format!("the trait bound `{trait_predicate}` is not satisfied{post_message}")
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 {
2952+
format!(
2953+
"the trait `{}` is not implemented for `{}`{post_message}",
2954+
pred.print_modifiers_and_trait_path(),
2955+
self.tcx.short_ty_string(pred.self_ty(), &mut None),
2956+
)
2957+
} else {
2958+
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
2959+
// not implemented for `T`".
2960+
format!("the trait bound `{pred}` is not satisfied{post_message}")
2961+
}
29452962
})
29462963
}
29472964

tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct Test {
3434
span: Span,
3535
/// A doc comment
3636
arg: NotIntoDiagnosticArg,
37-
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
37+
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
3838
}
3939

4040
#[derive(Subdiagnostic)]
@@ -44,5 +44,5 @@ struct SubTest {
4444
span: Span,
4545
/// A doc comment
4646
arg: NotIntoDiagnosticArg,
47-
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
47+
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
4848
}

tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
1+
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
22
--> $DIR/diagnostic-derive-doc-comment-field.rs:36:10
33
|
44
LL | #[derive(Diagnostic)]
@@ -12,7 +12,7 @@ note: required by a bound in `Diag::<'a, G>::arg`
1212
--> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC
1313
= note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

15-
error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied
15+
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg`
1616
--> $DIR/diagnostic-derive-doc-comment-field.rs:46:10
1717
|
1818
LL | #[derive(Subdiagnostic)]

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ struct ArgFieldWithoutSkip {
347347
#[primary_span]
348348
span: Span,
349349
other: Hello,
350-
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
350+
//~^ ERROR trait `IntoDiagnosticArg` is not implemented for `Hello`
351351
}
352352

353353
#[derive(Diagnostic)]

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ LL | #[derive(Diagnostic)]
618618
|
619619
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
620620

621-
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
621+
error[E0277]: the trait `IntoDiagnosticArg` is not implemented for `Hello`
622622
--> $DIR/diagnostic-derive.rs:349:12
623623
|
624624
LL | #[derive(Diagnostic)]

tests/ui/allocator/not-an-allocator.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
1+
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
22
--> $DIR/not-an-allocator.rs:2:11
33
|
44
LL | #[global_allocator]
@@ -9,7 +9,7 @@ LL | static A: usize = 0;
99
= help: the trait `GlobalAlloc` is implemented for `System`
1010
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

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

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

36-
error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
36+
error[E0277]: the trait `GlobalAlloc` is not implemented for `usize`
3737
--> $DIR/not-an-allocator.rs:2:11
3838
|
3939
LL | #[global_allocator]

tests/ui/array-slice-vec/repeat_empty_ok.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ pub struct Header<'a> {
66

77
pub fn test() {
88
let headers = [Header{value: &[]}; 128];
9-
//~^ ERROR the trait bound
9+
//~^ ERROR the trait
1010
}
1111

1212
pub fn test2() {
1313
let headers = [Header{value: &[0]}; 128];
14-
//~^ ERROR the trait bound
14+
//~^ ERROR the trait
1515
}

tests/ui/array-slice-vec/repeat_empty_ok.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
1+
error[E0277]: the trait `Copy` is not implemented for `Header<'_>`
22
--> $DIR/repeat_empty_ok.rs:8:20
33
|
44
LL | let headers = [Header{value: &[]}; 128];
@@ -13,7 +13,7 @@ LL + #[derive(Copy)]
1313
LL | pub struct Header<'a> {
1414
|
1515

16-
error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
16+
error[E0277]: the trait `Copy` is not implemented for `Header<'_>`
1717
--> $DIR/repeat_empty_ok.rs:13:20
1818
|
1919
LL | let headers = [Header{value: &[0]}; 128];

tests/ui/associated-consts/associated-const-array-len.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ trait Foo {
33
}
44

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

88
fn main() {
99
assert_eq!(1, X);

0 commit comments

Comments
 (0)