Skip to content

Commit 05aba31

Browse files
authored
Unrolled build for rust-lang#121875
Rollup merge of rust-lang#121875 - estebank:e0277-drive-by, r=compiler-errors Account for unmet T: !Copy in E0277 message ``` error[E0277]: the trait bound `T: !Copy` is not satisfied --> $DIR/simple.rs:10:16 | LL | not_copy::<T>(); | ^ the trait bound `T: !Copy` is not satisfied ``` instead of the current ``` error[E0277]: the trait bound `T: !Copy` is not satisfied --> $DIR/simple.rs:10:16 | LL | not_copy::<T>(); | ^ the trait `!Copy` is not implemented for `T` ```
2 parents 2e3581b + 7f97dfe commit 05aba31

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

+13-12
Original file line numberDiff line numberDiff line change
@@ -4769,20 +4769,21 @@ 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,
4772+
let desc = match ty_desc {
4773+
Some(desc) => format!(" {desc}"),
4774+
None => String::new(),
4775+
};
4776+
if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
4777+
format!(
4778+
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
47834779
trait_predicate.print_modifiers_and_trait_path(),
47844780
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4785-
),
4781+
)
4782+
} else {
4783+
// "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is
4784+
// not implemented for `T`".
4785+
// FIXME: add note explaining explicit negative trait bounds.
4786+
format!("{pre_message}the trait bound `{trait_predicate}` is not satisfied{post}")
47864787
}
47874788
}
47884789
}

tests/ui/traits/negative-bounds/simple.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: !Copy` is not satisfied
22
--> $DIR/simple.rs:10:16
33
|
44
LL | not_copy::<T>();
5-
| ^ the trait `!Copy` is not implemented for `T`
5+
| ^ the trait bound `T: !Copy` is not satisfied
66
|
77
note: required by a bound in `not_copy`
88
--> $DIR/simple.rs:3:16
@@ -14,7 +14,7 @@ error[E0277]: the trait bound `T: !Copy` is not satisfied
1414
--> $DIR/simple.rs:15:16
1515
|
1616
LL | not_copy::<T>();
17-
| ^ the trait `!Copy` is not implemented for `T`
17+
| ^ the trait bound `T: !Copy` is not satisfied
1818
|
1919
note: required by a bound in `not_copy`
2020
--> $DIR/simple.rs:3:16
@@ -26,7 +26,7 @@ error[E0277]: the trait bound `Copyable: !Copy` is not satisfied
2626
--> $DIR/simple.rs:30:16
2727
|
2828
LL | not_copy::<Copyable>();
29-
| ^^^^^^^^ the trait `!Copy` is not implemented for `Copyable`
29+
| ^^^^^^^^ the trait bound `Copyable: !Copy` is not satisfied
3030
|
3131
= help: the trait `Copy` is implemented for `Copyable`
3232
note: required by a bound in `not_copy`
@@ -44,7 +44,7 @@ error[E0277]: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
4444
--> $DIR/simple.rs:37:16
4545
|
4646
LL | not_copy::<NotNecessarilyCopyable>();
47-
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `!Copy` is not implemented for `NotNecessarilyCopyable`
47+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
4848
|
4949
note: required by a bound in `not_copy`
5050
--> $DIR/simple.rs:3:16

0 commit comments

Comments
 (0)