@@ -321,10 +321,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
321321 } else if let ty:: Param ( p) = lhs_ty. kind {
322322 suggest_constraining_param (
323323 self . tcx ,
324+ self . body_id ,
324325 & mut err,
325326 lhs_ty,
326327 rhs_ty,
327- & expr,
328328 missing_trait,
329329 p,
330330 false ,
@@ -481,10 +481,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
481481 } else if let ty:: Param ( p) = lhs_ty. kind {
482482 suggest_constraining_param (
483483 self . tcx ,
484+ self . body_id ,
484485 & mut err,
485486 lhs_ty,
486487 rhs_ty,
487- & expr,
488488 missing_trait,
489489 p,
490490 use_output,
@@ -938,10 +938,10 @@ fn suggest_impl_missing(err: &mut DiagnosticBuilder<'_>, ty: Ty<'_>, missing_tra
938938
939939fn suggest_constraining_param (
940940 tcx : TyCtxt < ' _ > ,
941+ body_id : hir:: HirId ,
941942 mut err : & mut DiagnosticBuilder < ' _ > ,
942943 lhs_ty : Ty < ' _ > ,
943944 rhs_ty : Ty < ' _ > ,
944- expr : & hir:: Expr < ' _ > ,
945945 missing_trait : & str ,
946946 p : ty:: ParamTy ,
947947 set_output : bool ,
@@ -951,33 +951,26 @@ fn suggest_constraining_param(
951951 // Try to find the def-id and details for the parameter p. We have only the index,
952952 // so we have to find the enclosing function's def-id, then look through its declared
953953 // generic parameters to get the declaration.
954- if let Some ( def_id) = hir
955- . find ( hir. get_parent_item ( expr. hir_id ) )
956- . and_then ( |node| node. hir_id ( ) )
957- . and_then ( |hir_id| hir. opt_local_def_id ( hir_id) )
954+ let def_id = hir. body_owner_def_id ( hir:: BodyId { hir_id : body_id } ) ;
955+ let generics = tcx. generics_of ( def_id) ;
956+ let param_def_id = generics. type_param ( & p, tcx) . def_id ;
957+ if let Some ( generics) = hir
958+ . as_local_hir_id ( param_def_id)
959+ . and_then ( |id| hir. find ( hir. get_parent_item ( id) ) )
960+ . as_ref ( )
961+ . and_then ( |node| node. generics ( ) )
958962 {
959- let generics = tcx. generics_of ( def_id) ;
960- let param_def_id = generics. type_param ( & p, tcx) . def_id ;
961- if let Some ( generics) = hir
962- . as_local_hir_id ( param_def_id)
963- . and_then ( |id| hir. find ( hir. get_parent_item ( id) ) )
964- . as_ref ( )
965- . and_then ( |node| node. generics ( ) )
966- {
967- let output = if set_output { format ! ( "<Output = {}>" , rhs_ty) } else { String :: new ( ) } ;
968- suggest_constraining_type_param (
969- tcx,
970- generics,
971- & mut err,
972- & format ! ( "{}" , lhs_ty) ,
973- & format ! ( "{}{}" , missing_trait, output) ,
974- None ,
975- ) ;
976- } else {
977- let span = tcx. def_span ( param_def_id) ;
978- err. span_label ( span, msg) ;
979- }
963+ let output = if set_output { format ! ( "<Output = {}>" , rhs_ty) } else { String :: new ( ) } ;
964+ suggest_constraining_type_param (
965+ tcx,
966+ generics,
967+ & mut err,
968+ & format ! ( "{}" , lhs_ty) ,
969+ & format ! ( "{}{}" , missing_trait, output) ,
970+ None ,
971+ ) ;
980972 } else {
981- err. note ( & msg) ;
973+ let span = tcx. def_span ( param_def_id) ;
974+ err. span_label ( span, msg) ;
982975 }
983976}
0 commit comments