@@ -98,6 +98,8 @@ pub trait TypeErrCtxtExt<'tcx> {
98
98
error : & SelectionError < ' tcx > ,
99
99
) ;
100
100
101
+ fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool ;
102
+
101
103
fn report_const_param_not_wf (
102
104
& self ,
103
105
ty : Ty < ' tcx > ,
@@ -157,12 +159,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
157
159
predicate : error. obligation . predicate ,
158
160
index : Some ( index) ,
159
161
} ) ;
160
-
161
- self . reported_trait_errors
162
- . borrow_mut ( )
163
- . entry ( span)
164
- . or_default ( )
165
- . push ( error. obligation . predicate ) ;
166
162
}
167
163
168
164
// We do this in 2 passes because we want to display errors in order, though
@@ -200,6 +196,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
200
196
for ( error, suppressed) in iter:: zip ( & errors, & is_suppressed) {
201
197
if !suppressed && error. obligation . cause . span . from_expansion ( ) == from_expansion {
202
198
self . report_fulfillment_error ( error) ;
199
+ // We want to ignore desugarings here: spans are equivalent even
200
+ // if one is the result of a desugaring and the other is not.
201
+ let mut span = error. obligation . cause . span ;
202
+ let expn_data = span. ctxt ( ) . outer_expn_data ( ) ;
203
+ if let ExpnKind :: Desugaring ( _) = expn_data. kind {
204
+ span = expn_data. call_site ;
205
+ }
206
+ self . reported_trait_errors
207
+ . borrow_mut ( )
208
+ . entry ( span)
209
+ . or_default ( )
210
+ . push ( error. obligation . predicate ) ;
203
211
}
204
212
}
205
213
}
@@ -412,6 +420,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
412
420
{
413
421
return ;
414
422
}
423
+ if self . fn_arg_obligation ( & obligation) {
424
+ // Silence redundant errors on binding acccess that are already
425
+ // reported on the binding definition (#56607).
426
+ return ;
427
+ }
415
428
let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
416
429
417
430
let ( post_message, pre_message, type_def) = self
@@ -908,6 +921,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
908
921
err. emit ( ) ;
909
922
}
910
923
924
+ fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool {
925
+ if let ObligationCauseCode :: FunctionArgumentObligation {
926
+ arg_hir_id,
927
+ ..
928
+ } = obligation. cause . code ( )
929
+ && let Some ( Node :: Expr ( arg) ) = self . tcx . hir ( ) . find ( * arg_hir_id)
930
+ && let arg = arg. peel_borrows ( )
931
+ && let hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
932
+ None ,
933
+ hir:: Path { res : hir:: def:: Res :: Local ( hir_id) , .. } ,
934
+ ) ) = arg. kind
935
+ && let Some ( Node :: Pat ( pat) ) = self . tcx . hir ( ) . find ( * hir_id)
936
+ && let Some ( preds) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
937
+ && preds. contains ( & obligation. predicate )
938
+ {
939
+ return true ;
940
+ }
941
+ false
942
+ }
943
+
911
944
fn report_const_param_not_wf (
912
945
& self ,
913
946
ty : Ty < ' tcx > ,
0 commit comments