File tree 2 files changed +16
-9
lines changed
compiler/rustc_trait_selection/src/traits/error_reporting
tests/ui/traits/negative-bounds
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -4773,11 +4773,18 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
4773
4773
Some ( desc) => format ! ( " {desc}" ) ,
4774
4774
None => String :: new ( ) ,
4775
4775
} ;
4776
- format ! (
4777
- "{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}" ,
4778
- trait_predicate. print_modifiers_and_trait_path( ) ,
4779
- tcx. short_ty_string( trait_ref. skip_binder( ) . self_ty( ) , & mut None ) ,
4780
- )
4776
+ if let ty:: ImplPolarity :: Positive = trait_predicate. polarity ( ) {
4777
+ format ! (
4778
+ "{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}" ,
4779
+ trait_predicate. print_modifiers_and_trait_path( ) ,
4780
+ tcx. short_ty_string( trait_ref. skip_binder( ) . self_ty( ) , & mut None ) ,
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}" )
4787
+ }
4781
4788
}
4782
4789
}
4783
4790
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: !Copy` is not satisfied
2
2
--> $DIR/simple.rs:10:16
3
3
|
4
4
LL | not_copy::<T>();
5
- | ^ the trait ` !Copy` is not implemented for `T`
5
+ | ^ the trait bound `T: !Copy` is not satisfied
6
6
|
7
7
note: required by a bound in `not_copy`
8
8
--> $DIR/simple.rs:3:16
@@ -14,7 +14,7 @@ error[E0277]: the trait bound `T: !Copy` is not satisfied
14
14
--> $DIR/simple.rs:15:16
15
15
|
16
16
LL | not_copy::<T>();
17
- | ^ the trait ` !Copy` is not implemented for `T`
17
+ | ^ the trait bound `T: !Copy` is not satisfied
18
18
|
19
19
note: required by a bound in `not_copy`
20
20
--> $DIR/simple.rs:3:16
@@ -26,7 +26,7 @@ error[E0277]: the trait bound `Copyable: !Copy` is not satisfied
26
26
--> $DIR/simple.rs:30:16
27
27
|
28
28
LL | not_copy::<Copyable>();
29
- | ^^^^^^^^ the trait ` !Copy` is not implemented for `Copyable`
29
+ | ^^^^^^^^ the trait bound `Copyable: !Copy` is not satisfied
30
30
|
31
31
= help: the trait `Copy` is implemented for `Copyable`
32
32
note: required by a bound in `not_copy`
@@ -44,7 +44,7 @@ error[E0277]: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
44
44
--> $DIR/simple.rs:37:16
45
45
|
46
46
LL | not_copy::<NotNecessarilyCopyable>();
47
- | ^^^^^^^^^^^^^^^^^^^^^^ the trait ` !Copy` is not implemented for `NotNecessarilyCopyable`
47
+ | ^^^^^^^^^^^^^^^^^^^^^^ the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
48
48
|
49
49
note: required by a bound in `not_copy`
50
50
--> $DIR/simple.rs:3:16
You can’t perform that action at this time.
0 commit comments