@@ -19,7 +19,7 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
1919use rustc_middle:: ty:: { self , InferConst } ;
2020use rustc_middle:: ty:: { GenericArg , GenericArgKind , GenericArgsRef } ;
2121use rustc_middle:: ty:: { IsSuggestable , Ty , TyCtxt , TypeckResults } ;
22- use rustc_span:: symbol:: { kw , sym, Ident } ;
22+ use rustc_span:: symbol:: { sym, Ident } ;
2323use rustc_span:: { BytePos , Span } ;
2424use std:: borrow:: Cow ;
2525use std:: iter;
@@ -162,8 +162,10 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
162162 let ty_vars = infcx_inner. type_variables ( ) ;
163163 let var_origin = ty_vars. var_origin ( ty_vid) ;
164164 if let Some ( def_id) = var_origin. param_def_id
165+ // The `Self` param of a trait has the def-id of the trait,
166+ // since it's a synthetic parameter.
167+ && infcx. tcx . def_kind ( def_id) == DefKind :: TyParam
165168 && let name = infcx. tcx . item_name ( def_id)
166- && name != kw:: SelfUpper
167169 && !var_origin. span . from_expansion ( )
168170 {
169171 let generics = infcx. tcx . generics_of ( infcx. tcx . parent ( def_id) ) ;
@@ -277,20 +279,18 @@ impl<'tcx> InferCtxt<'tcx> {
277279 let mut inner = self . inner . borrow_mut ( ) ;
278280 let ty_vars = & inner. type_variables ( ) ;
279281 let var_origin = ty_vars. var_origin ( ty_vid) ;
280- if let Some ( def_id) = var_origin. param_def_id {
281- let name = self . tcx . item_name ( def_id) ;
282- if name != kw:: SelfUpper && !var_origin. span . from_expansion ( ) {
283- return InferenceDiagnosticsData {
284- name : name. to_string ( ) ,
285- span : Some ( var_origin. span ) ,
286- kind : UnderspecifiedArgKind :: Type {
287- prefix : "type parameter" . into ( ) ,
288- } ,
289- parent : InferenceDiagnosticsParentData :: for_def_id (
290- self . tcx , def_id,
291- ) ,
292- } ;
293- }
282+ if let Some ( def_id) = var_origin. param_def_id
283+ // The `Self` param of a trait has the def-id of the trait,
284+ // since it's a synthetic parameter.
285+ && self . tcx . def_kind ( def_id) == DefKind :: TyParam
286+ && !var_origin. span . from_expansion ( )
287+ {
288+ return InferenceDiagnosticsData {
289+ name : self . tcx . item_name ( def_id) . to_string ( ) ,
290+ span : Some ( var_origin. span ) ,
291+ kind : UnderspecifiedArgKind :: Type { prefix : "type parameter" . into ( ) } ,
292+ parent : InferenceDiagnosticsParentData :: for_def_id ( self . tcx , def_id) ,
293+ } ;
294294 }
295295 }
296296
0 commit comments