Skip to content

Commit ede2ddf

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 bf9c7a6 commit ede2ddf

File tree

739 files changed

+1423
-1403
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

+1423
-1403
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,21 +4774,23 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
47744774
} else {
47754775
String::new()
47764776
};
4777-
match ty_desc {
4778-
Some(desc) => format!(
4779-
"{}the trait `{}` is not implemented for {} `{}`{post}",
4780-
pre_message,
4781-
trait_predicate.print_modifiers_and_trait_path(),
4782-
desc,
4783-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4784-
),
4785-
None => format!(
4786-
"{}the trait `{}` is not implemented for `{}`{post}",
4787-
pre_message,
4788-
trait_predicate.print_modifiers_and_trait_path(),
4789-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4790-
),
4791-
}
4777+
let desc = match ty_desc {
4778+
Some(desc) => format!(" {desc}"),
4779+
None => String::new(),
4780+
};
4781+
4782+
let pred = tcx.erase_regions(if tcx.features().non_lifetime_binders {
4783+
// We can't erase the lifetime bounds on their own when this feature is enabled.
4784+
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
4785+
trait_predicate.skip_binder()
4786+
} else {
4787+
tcx.instantiate_bound_regions_with_erased(*trait_predicate)
4788+
});
4789+
format!(
4790+
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
4791+
pred.print_modifiers_and_trait_path(),
4792+
tcx.short_ty_string(pred.self_ty(), &mut None),
4793+
)
47924794
}
47934795
}
47944796

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
@@ -2950,7 +2950,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
29502950
}
29512951
})
29522952
.unwrap_or_else(|| {
2953-
format!("the trait bound `{trait_predicate}` is not satisfied{post_message}")
2953+
let pred = self.tcx.erase_regions(if self.tcx.features().non_lifetime_binders {
2954+
// We can't erase the lifetime bounds on their own when this feature is enabled.
2955+
// `instantiate_bound_regions_with_erased` expects there to be no type bounds.
2956+
trait_predicate.skip_binder()
2957+
} else {
2958+
self.tcx.instantiate_bound_regions_with_erased(*trait_predicate)
2959+
});
2960+
if let ty::ImplPolarity::Positive = pred.polarity {
2961+
format!(
2962+
"the trait `{}` is not implemented for `{}`{post_message}",
2963+
pred.print_modifiers_and_trait_path(),
2964+
self.tcx.short_ty_string(pred.self_ty(), &mut None),
2965+
)
2966+
} else {
2967+
// "the trait bound `!Send: T` is not satisfied" reads better than "`!Send` is
2968+
// not implemented for `T`".
2969+
format!("the trait bound `{pred}` is not satisfied{post_message}")
2970+
}
29542971
})
29552972
}
29562973

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 `DiagnosticBuilder::<'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)