File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed
compiler/rustc_trait_selection/src/traits/error_reporting
tests/ui/traits/negative-bounds Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -4752,20 +4752,21 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
47524752 } else {
47534753 String :: new ( )
47544754 } ;
4755- match ty_desc {
4756- Some ( desc) => format ! (
4757- "{}the trait `{}` is not implemented for {} `{}`{post}" ,
4758- pre_message,
4759- trait_predicate. print_modifiers_and_trait_path( ) ,
4760- desc,
4761- tcx. short_ty_string( trait_ref. skip_binder( ) . self_ty( ) , & mut None ) ,
4762- ) ,
4763- None => format ! (
4764- "{}the trait `{}` is not implemented for `{}`{post}" ,
4765- pre_message,
4755+ let desc = match ty_desc {
4756+ Some ( desc) => format ! ( " {desc}" ) ,
4757+ None => String :: new ( ) ,
4758+ } ;
4759+ if let ty:: ImplPolarity :: Positive = trait_predicate. polarity ( ) {
4760+ format ! (
4761+ "{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}" ,
47664762 trait_predicate. print_modifiers_and_trait_path( ) ,
47674763 tcx. short_ty_string( trait_ref. skip_binder( ) . self_ty( ) , & mut None ) ,
4768- ) ,
4764+ )
4765+ } else {
4766+ // "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is
4767+ // not implemented for `T`".
4768+ // FIXME: add note explaining explicit negative trait bounds.
4769+ format ! ( "{pre_message}the trait bound `{trait_predicate}` is not satisfied{post}" )
47694770 }
47704771 }
47714772}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: !Copy` is not satisfied
22 --> $DIR/simple.rs:10:16
33 |
44LL | not_copy::<T>();
5- | ^ the trait ` !Copy` is not implemented for `T`
5+ | ^ the trait bound `T: !Copy` is not satisfied
66 |
77note: 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 |
1616LL | not_copy::<T>();
17- | ^ the trait ` !Copy` is not implemented for `T`
17+ | ^ the trait bound `T: !Copy` is not satisfied
1818 |
1919note: 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 |
2828LL | 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`
3232note: 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 |
4646LL | not_copy::<NotNecessarilyCopyable>();
47- | ^^^^^^^^^^^^^^^^^^^^^^ the trait ` !Copy` is not implemented for `NotNecessarilyCopyable`
47+ | ^^^^^^^^^^^^^^^^^^^^^^ the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
4848 |
4949note: required by a bound in `not_copy`
5050 --> $DIR/simple.rs:3:16
You can’t perform that action at this time.
0 commit comments