@@ -163,12 +163,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
163163 predicate : error. obligation . predicate ,
164164 index : Some ( index) ,
165165 } ) ;
166-
167- self . reported_trait_errors
168- . borrow_mut ( )
169- . entry ( span)
170- . or_default ( )
171- . push ( error. obligation . predicate ) ;
172166 }
173167
174168 // We do this in 2 passes because we want to display errors in order, though
@@ -206,6 +200,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
206200 for ( error, suppressed) in iter:: zip ( & errors, & is_suppressed) {
207201 if !suppressed && error. obligation . cause . span . from_expansion ( ) == from_expansion {
208202 self . report_fulfillment_error ( error) ;
203+ // We want to ignore desugarings here: spans are equivalent even
204+ // if one is the result of a desugaring and the other is not.
205+ let mut span = error. obligation . cause . span ;
206+ let expn_data = span. ctxt ( ) . outer_expn_data ( ) ;
207+ if let ExpnKind :: Desugaring ( _) = expn_data. kind {
208+ span = expn_data. call_site ;
209+ }
210+ self . reported_trait_errors
211+ . borrow_mut ( )
212+ . entry ( span)
213+ . or_default ( )
214+ . push ( error. obligation . predicate ) ;
209215 }
210216 }
211217 }
@@ -441,7 +447,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
441447 && let Some ( Node :: Pat ( pat) ) = self . tcx . hir ( ) . find ( * hir_id)
442448 && let Some ( preds) = self . reported_trait_errors . borrow ( ) . get ( & pat. span )
443449 && preds. contains ( & obligation. predicate )
444- && self . tcx . sess . has_errors ( ) . is_some ( )
445450 {
446451 // Silence redundant errors on binding acccess that are already
447452 // reported on the binding definition (#56607).
0 commit comments