@@ -321,10 +321,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
321
321
} else if let ty:: Param ( p) = lhs_ty. kind {
322
322
suggest_constraining_param (
323
323
self . tcx ,
324
+ self . body_id ,
324
325
& mut err,
325
326
lhs_ty,
326
327
rhs_ty,
327
- & expr,
328
328
missing_trait,
329
329
p,
330
330
false ,
@@ -481,10 +481,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
481
481
} else if let ty:: Param ( p) = lhs_ty. kind {
482
482
suggest_constraining_param (
483
483
self . tcx ,
484
+ self . body_id ,
484
485
& mut err,
485
486
lhs_ty,
486
487
rhs_ty,
487
- & expr,
488
488
missing_trait,
489
489
p,
490
490
use_output,
@@ -938,10 +938,10 @@ fn suggest_impl_missing(err: &mut DiagnosticBuilder<'_>, ty: Ty<'_>, missing_tra
938
938
939
939
fn suggest_constraining_param (
940
940
tcx : TyCtxt < ' _ > ,
941
+ body_id : hir:: HirId ,
941
942
mut err : & mut DiagnosticBuilder < ' _ > ,
942
943
lhs_ty : Ty < ' _ > ,
943
944
rhs_ty : Ty < ' _ > ,
944
- expr : & hir:: Expr < ' _ > ,
945
945
missing_trait : & str ,
946
946
p : ty:: ParamTy ,
947
947
set_output : bool ,
@@ -951,33 +951,26 @@ fn suggest_constraining_param(
951
951
// Try to find the def-id and details for the parameter p. We have only the index,
952
952
// so we have to find the enclosing function's def-id, then look through its declared
953
953
// 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 ( ) )
958
962
{
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
+ ) ;
980
972
} else {
981
- err. note ( & msg) ;
973
+ let span = tcx. def_span ( param_def_id) ;
974
+ err. span_label ( span, msg) ;
982
975
}
983
976
}
0 commit comments