@@ -104,6 +104,8 @@ pub trait TypeErrCtxtExt<'tcx> {
104104 error : & SelectionError < ' tcx > ,
105105 ) ;
106106
107+ fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool ;
108+
107109 fn report_const_param_not_wf (
108110 & self ,
109111 ty : Ty < ' tcx > ,
@@ -434,20 +436,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
434436 {
435437 return ;
436438 }
437- if let ObligationCauseCode :: FunctionArgumentObligation {
438- arg_hir_id,
439- ..
440- } = obligation. cause . code ( )
441- && let Some ( Node :: Expr ( arg) ) = self . tcx . hir ( ) . find ( * arg_hir_id)
442- && let arg = arg. peel_borrows ( )
443- && let hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
444- None ,
445- hir:: Path { res : hir:: def:: Res :: Local ( hir_id) , .. } ,
446- ) ) = arg. kind
447- && let Some ( Node :: Pat ( pat) ) = self . tcx . hir ( ) . find ( * hir_id)
448- && let Some ( preds) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
449- && preds. contains ( & obligation. predicate )
450- {
439+ if self . fn_arg_obligation ( & obligation) {
451440 // Silence redundant errors on binding acccess that are already
452441 // reported on the binding definition (#56607).
453442 return ;
@@ -948,6 +937,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
948937 err. emit ( ) ;
949938 }
950939
940+ fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool {
941+ if let ObligationCauseCode :: FunctionArgumentObligation {
942+ arg_hir_id,
943+ ..
944+ } = obligation. cause . code ( )
945+ && let Some ( Node :: Expr ( arg) ) = self . tcx . hir ( ) . find ( * arg_hir_id)
946+ && let arg = arg. peel_borrows ( )
947+ && let hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
948+ None ,
949+ hir:: Path { res : hir:: def:: Res :: Local ( hir_id) , .. } ,
950+ ) ) = arg. kind
951+ && let Some ( Node :: Pat ( pat) ) = self . tcx . hir ( ) . find ( * hir_id)
952+ && let Some ( preds) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
953+ && preds. contains ( & obligation. predicate )
954+ {
955+ return true ;
956+ }
957+ false
958+ }
959+
951960 fn report_const_param_not_wf (
952961 & self ,
953962 ty : Ty < ' tcx > ,
0 commit comments