@@ -241,7 +241,7 @@ impl<'tcx> ty::TyS<'tcx> {
241241 ty:: Infer ( ty:: FreshFloatTy ( _) ) => "fresh floating-point type" . into ( ) ,
242242 ty:: Projection ( _) => "associated type" . into ( ) ,
243243 ty:: UnnormalizedProjection ( _) => "non-normalized associated type" . into ( ) ,
244- ty:: Param ( _ ) => "type parameter" . into ( ) ,
244+ ty:: Param ( p ) => format ! ( "type parameter `{}`" , p ) . into ( ) ,
245245 ty:: Opaque ( ..) => "opaque type" . into ( ) ,
246246 ty:: Error => "type error" . into ( ) ,
247247 }
@@ -254,6 +254,7 @@ impl<'tcx> TyCtxt<'tcx> {
254254 db : & mut DiagnosticBuilder < ' _ > ,
255255 err : & TypeError < ' tcx > ,
256256 sp : Span ,
257+ body_owner_def_id : DefId ,
257258 ) {
258259 use self :: TypeError :: * ;
259260
@@ -288,7 +289,16 @@ impl<'tcx> TyCtxt<'tcx> {
288289 ) ;
289290 }
290291 } ,
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+ }
292302 db. note ( "a type parameter was expected, but a different one was found; \
293303 you might be missing a type parameter or trait bound") ;
294304 db. note ( "for more information, visit \
@@ -301,7 +311,12 @@ impl<'tcx> TyCtxt<'tcx> {
301311 ( ty:: Param ( _) , ty:: Projection ( _) ) | ( ty:: Projection ( _) , ty:: Param ( _) ) => {
302312 db. note ( "you might be missing a type parameter or trait bound" ) ;
303313 }
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+ }
305320 db. help ( "type parameters must be constrained to match other types" ) ;
306321 if self . sess . teach ( & db. get_code ( ) . unwrap ( ) ) {
307322 db. help ( "given a type parameter `T` and a method `foo`:
0 commit comments