@@ -19,7 +19,7 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
19
19
use rustc_middle:: ty:: { self , InferConst } ;
20
20
use rustc_middle:: ty:: { GenericArg , GenericArgKind , GenericArgsRef } ;
21
21
use rustc_middle:: ty:: { IsSuggestable , Ty , TyCtxt , TypeckResults } ;
22
- use rustc_span:: symbol:: { kw , sym, Ident } ;
22
+ use rustc_span:: symbol:: { sym, Ident } ;
23
23
use rustc_span:: { BytePos , Span } ;
24
24
use std:: borrow:: Cow ;
25
25
use std:: iter;
@@ -162,8 +162,10 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
162
162
let ty_vars = infcx_inner. type_variables ( ) ;
163
163
let var_origin = ty_vars. var_origin ( ty_vid) ;
164
164
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
165
168
&& let name = infcx. tcx . item_name ( def_id)
166
- && name != kw:: SelfUpper
167
169
&& !var_origin. span . from_expansion ( )
168
170
{
169
171
let generics = infcx. tcx . generics_of ( infcx. tcx . parent ( def_id) ) ;
@@ -277,20 +279,18 @@ impl<'tcx> InferCtxt<'tcx> {
277
279
let mut inner = self . inner . borrow_mut ( ) ;
278
280
let ty_vars = & inner. type_variables ( ) ;
279
281
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
+ } ;
294
294
}
295
295
}
296
296
0 commit comments