@@ -241,7 +241,7 @@ impl<'tcx> ty::TyS<'tcx> {
241
241
ty:: Infer ( ty:: FreshFloatTy ( _) ) => "fresh floating-point type" . into ( ) ,
242
242
ty:: Projection ( _) => "associated type" . into ( ) ,
243
243
ty:: UnnormalizedProjection ( _) => "non-normalized associated type" . into ( ) ,
244
- ty:: Param ( _ ) => "type parameter" . into ( ) ,
244
+ ty:: Param ( p ) => format ! ( "type parameter `{}`" , p ) . into ( ) ,
245
245
ty:: Opaque ( ..) => "opaque type" . into ( ) ,
246
246
ty:: Error => "type error" . into ( ) ,
247
247
}
@@ -254,6 +254,7 @@ impl<'tcx> TyCtxt<'tcx> {
254
254
db : & mut DiagnosticBuilder < ' _ > ,
255
255
err : & TypeError < ' tcx > ,
256
256
sp : Span ,
257
+ body_owner_def_id : DefId ,
257
258
) {
258
259
use self :: TypeError :: * ;
259
260
@@ -288,7 +289,16 @@ impl<'tcx> TyCtxt<'tcx> {
288
289
) ;
289
290
}
290
291
} ,
291
- ( ty:: Param ( _) , ty:: Param ( _) ) => {
292
+ ( ty:: Param ( expected) , ty:: Param ( found) ) => {
293
+ let generics = self . generics_of ( body_owner_def_id) ;
294
+ let e_span = self . def_span ( generics. type_param ( expected, self ) . def_id ) ;
295
+ if !sp. contains ( e_span) {
296
+ db. span_label ( e_span, "expected type parameter" ) ;
297
+ }
298
+ let f_span = self . def_span ( generics. type_param ( found, self ) . def_id ) ;
299
+ if !sp. contains ( f_span) {
300
+ db. span_label ( f_span, "found type parameter" ) ;
301
+ }
292
302
db. note ( "a type parameter was expected, but a different one was found; \
293
303
you might be missing a type parameter or trait bound") ;
294
304
db. note ( "for more information, visit \
@@ -301,7 +311,12 @@ impl<'tcx> TyCtxt<'tcx> {
301
311
( ty:: Param ( _) , ty:: Projection ( _) ) | ( ty:: Projection ( _) , ty:: Param ( _) ) => {
302
312
db. note ( "you might be missing a type parameter or trait bound" ) ;
303
313
}
304
- ( ty:: Param ( _) , _) | ( _, ty:: Param ( _) ) => {
314
+ ( ty:: Param ( p) , _) | ( _, ty:: Param ( p) ) => {
315
+ let generics = self . generics_of ( body_owner_def_id) ;
316
+ let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
317
+ if !sp. contains ( p_span) {
318
+ db. span_label ( p_span, "this type parameter" ) ;
319
+ }
305
320
db. help ( "type parameters must be constrained to match other types" ) ;
306
321
if self . sess . teach ( & db. get_code ( ) . unwrap ( ) ) {
307
322
db. help ( "given a type parameter `T` and a method `foo`:
0 commit comments