@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99use rustc_macros:: LintDiagnostic ;
1010use rustc_middle:: bug;
1111use 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 } ;
1313use rustc_parse_format:: { ParseMode , Parser , Piece , Position } ;
1414use rustc_session:: lint:: builtin:: UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ;
1515use rustc_span:: Span ;
@@ -108,14 +108,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
108108
109109 pub fn on_unimplemented_note (
110110 & self ,
111- trait_ref : ty:: PolyTraitRef < ' tcx > ,
111+ trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
112112 obligation : & PredicateObligation < ' tcx > ,
113113 long_ty_file : & mut Option < PathBuf > ,
114114 ) -> OnUnimplementedNote {
115+ if trait_pred. polarity ( ) != ty:: PredicatePolarity :: Positive {
116+ return OnUnimplementedNote :: default ( ) ;
117+ }
118+
115119 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 ( ) ;
119123
120124 let mut flags = vec ! [ ] ;
121125 // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
@@ -144,13 +148,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
144148 flags. push ( ( sym:: cause, Some ( "MainFunctionType" . to_string ( ) ) ) ) ;
145149 }
146150
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 ( ) ) ) ) ;
148152
149153 // Add all types without trimmed paths or visible paths, ensuring they end up with
150154 // their "canonical" def path.
151155 ty:: print:: with_no_trimmed_paths!( ty:: print:: with_no_visible_paths!( {
152156 let generics = self . tcx. generics_of( def_id) ;
153- let self_ty = trait_ref . self_ty( ) ;
157+ let self_ty = trait_pred . self_ty( ) ;
154158 // This is also included through the generics list as `Self`,
155159 // but the parser won't allow you to use it
156160 flags. push( ( sym:: _Self, Some ( self_ty. to_string( ) ) ) ) ;
@@ -266,7 +270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
266270 } ) ) ;
267271
268272 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)
270274 } else {
271275 OnUnimplementedNote :: default ( )
272276 }
0 commit comments