@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
9
9
use rustc_macros:: LintDiagnostic ;
10
10
use rustc_middle:: bug;
11
11
use rustc_middle:: ty:: print:: PrintTraitRefExt as _;
12
- use rustc_middle:: ty:: { self , GenericArgsRef , GenericParamDefKind , TyCtxt } ;
12
+ use rustc_middle:: ty:: { self , GenericArgsRef , GenericParamDefKind , ToPolyTraitRef , TyCtxt } ;
13
13
use rustc_parse_format:: { ParseMode , Parser , Piece , Position } ;
14
14
use rustc_session:: lint:: builtin:: UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ;
15
15
use rustc_span:: Span ;
@@ -108,14 +108,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
108
108
109
109
pub fn on_unimplemented_note (
110
110
& self ,
111
- trait_ref : ty:: PolyTraitRef < ' tcx > ,
111
+ trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
112
112
obligation : & PredicateObligation < ' tcx > ,
113
113
long_ty_file : & mut Option < PathBuf > ,
114
114
) -> OnUnimplementedNote {
115
+ if trait_pred. polarity ( ) != ty:: PredicatePolarity :: Positive {
116
+ return OnUnimplementedNote :: default ( ) ;
117
+ }
118
+
115
119
let ( def_id, args) = self
116
- . impl_similar_to ( trait_ref , obligation)
117
- . unwrap_or_else ( || ( trait_ref . def_id ( ) , trait_ref . skip_binder ( ) . args ) ) ;
118
- let trait_ref = trait_ref . skip_binder ( ) ;
120
+ . impl_similar_to ( trait_pred . to_poly_trait_ref ( ) , obligation)
121
+ . unwrap_or_else ( || ( trait_pred . def_id ( ) , trait_pred . skip_binder ( ) . trait_ref . args ) ) ;
122
+ let trait_pred = trait_pred . skip_binder ( ) ;
119
123
120
124
let mut flags = vec ! [ ] ;
121
125
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
@@ -144,13 +148,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
144
148
flags. push ( ( sym:: cause, Some ( "MainFunctionType" . to_string ( ) ) ) ) ;
145
149
}
146
150
147
- flags. push ( ( sym:: Trait , Some ( trait_ref. print_trait_sugared ( ) . to_string ( ) ) ) ) ;
151
+ flags. push ( ( sym:: Trait , Some ( trait_pred . trait_ref . print_trait_sugared ( ) . to_string ( ) ) ) ) ;
148
152
149
153
// Add all types without trimmed paths or visible paths, ensuring they end up with
150
154
// their "canonical" def path.
151
155
ty:: print:: with_no_trimmed_paths!( ty:: print:: with_no_visible_paths!( {
152
156
let generics = self . tcx. generics_of( def_id) ;
153
- let self_ty = trait_ref . self_ty( ) ;
157
+ let self_ty = trait_pred . self_ty( ) ;
154
158
// This is also included through the generics list as `Self`,
155
159
// but the parser won't allow you to use it
156
160
flags. push( ( sym:: _Self, Some ( self_ty. to_string( ) ) ) ) ;
@@ -266,7 +270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
266
270
} ) ) ;
267
271
268
272
if let Ok ( Some ( command) ) = OnUnimplementedDirective :: of_item ( self . tcx , def_id) {
269
- command. evaluate ( self . tcx , trait_ref, & flags, long_ty_file)
273
+ command. evaluate ( self . tcx , trait_pred . trait_ref , & flags, long_ty_file)
270
274
} else {
271
275
OnUnimplementedNote :: default ( )
272
276
}
0 commit comments