@@ -107,7 +107,10 @@ pub trait TypeErrCtxtExt<'tcx> {
107
107
trait_ref : ty:: PolyTraitRef < ' tcx > ,
108
108
) -> Option < ErrorGuaranteed > ;
109
109
110
- fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool ;
110
+ fn fn_arg_obligation (
111
+ & self ,
112
+ obligation : & PredicateObligation < ' tcx > ,
113
+ ) -> Result < ( ) , ErrorGuaranteed > ;
111
114
112
115
fn try_conversion_context (
113
116
& self ,
@@ -142,6 +145,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
142
145
(
143
146
span,
144
147
predicates
148
+ . 0
145
149
. iter ( )
146
150
. map ( |& predicate| ErrorDescriptor { predicate, index : None } )
147
151
. collect ( ) ,
@@ -213,7 +217,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
213
217
for from_expansion in [ false , true ] {
214
218
for ( error, suppressed) in iter:: zip ( & errors, & is_suppressed) {
215
219
if !suppressed && error. obligation . cause . span . from_expansion ( ) == from_expansion {
216
- reported = Some ( self . report_fulfillment_error ( error) ) ;
220
+ let guar = self . report_fulfillment_error ( error) ;
221
+ reported = Some ( guar) ;
217
222
// We want to ignore desugarings here: spans are equivalent even
218
223
// if one is the result of a desugaring and the other is not.
219
224
let mut span = error. obligation . cause . span ;
@@ -224,7 +229,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
224
229
self . reported_trait_errors
225
230
. borrow_mut ( )
226
231
. entry ( span)
227
- . or_default ( )
232
+ . or_insert_with ( || ( vec ! [ ] , guar) )
233
+ . 0
228
234
. push ( error. obligation . predicate ) ;
229
235
}
230
236
}
@@ -447,10 +453,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
447
453
{
448
454
return guar;
449
455
}
450
- if self . fn_arg_obligation ( & obligation ) {
451
- // Silence redundant errors on binding acccess that are already
452
- // reported on the binding definition (#56607).
453
- return self . dcx ( ) . span_delayed_bug ( obligation . cause . span , "error already reported" ) ;
456
+ // Silence redundant errors on binding acccess that are already
457
+ // reported on the binding definition (#56607).
458
+ if let Err ( guar ) = self . fn_arg_obligation ( & obligation ) {
459
+ return guar ;
454
460
}
455
461
let mut file = None ;
456
462
let ( post_message, pre_message, type_def) = self
@@ -981,7 +987,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
981
987
}
982
988
}
983
989
984
- fn fn_arg_obligation ( & self , obligation : & PredicateObligation < ' tcx > ) -> bool {
990
+ fn fn_arg_obligation (
991
+ & self ,
992
+ obligation : & PredicateObligation < ' tcx > ,
993
+ ) -> Result < ( ) , ErrorGuaranteed > {
985
994
if let ObligationCauseCode :: FunctionArgumentObligation { arg_hir_id, .. } =
986
995
obligation. cause . code ( )
987
996
&& let Some ( Node :: Expr ( arg) ) = self . tcx . opt_hir_node ( * arg_hir_id)
@@ -991,12 +1000,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
991
1000
hir:: Path { res : hir:: def:: Res :: Local ( hir_id) , .. } ,
992
1001
) ) = arg. kind
993
1002
&& let Some ( Node :: Pat ( pat) ) = self . tcx . opt_hir_node ( * hir_id)
994
- && let Some ( preds) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
1003
+ && let Some ( ( preds, guar ) ) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
995
1004
&& preds. contains ( & obligation. predicate )
996
1005
{
997
- return true ;
1006
+ return Err ( * guar ) ;
998
1007
}
999
- false
1008
+ Ok ( ( ) )
1000
1009
}
1001
1010
1002
1011
/// When the `E` of the resulting `Result<T, E>` in an expression `foo().bar().baz()?`,
0 commit comments