@@ -587,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587
587
588
588
// Find all the requirements that come from a local `impl` block.
589
589
let mut skip_list: FxHashSet < _ > = Default :: default ( ) ;
590
- let mut spanned_predicates: FxHashMap < MultiSpan , _ > = Default :: default ( ) ;
590
+ let mut spanned_predicates = FxHashMap :: default ( ) ;
591
591
for ( p, parent_p, impl_def_id, cause) in unsatisfied_predicates
592
592
. iter ( )
593
593
. filter_map ( |( p, parent, c) | c. as_ref ( ) . map ( |c| ( p, parent, c) ) )
@@ -615,13 +615,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
615
615
) =>
616
616
{
617
617
let span = self_ty. span . ctxt ( ) . outer_expn_data ( ) . call_site ;
618
- let mut spans: MultiSpan = span. into ( ) ;
619
- spans. push_span_label (
618
+ let entry = spanned_predicates. entry ( span) ;
619
+ let entry = entry. or_insert_with ( || {
620
+ ( FxHashSet :: default ( ) , FxHashSet :: default ( ) , Vec :: new ( ) )
621
+ } ) ;
622
+ entry. 0 . insert ( span) ;
623
+ entry. 1 . insert ( (
620
624
span,
621
625
"unsatisfied trait bound introduced in this `derive` macro" ,
622
- ) ;
623
- let entry = spanned_predicates . entry ( spans ) ;
624
- entry . or_insert_with ( || Vec :: new ( ) ) . push ( p) ;
626
+ ) ) ;
627
+ entry. 2 . push ( p ) ;
628
+ skip_list . insert ( p) ;
625
629
}
626
630
627
631
// Unmet obligation coming from an `impl`.
@@ -659,28 +663,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
659
663
let _ = format_pred ( * pred) ;
660
664
}
661
665
skip_list. insert ( p) ;
662
- let mut spans = if cause. span != * item_span {
663
- let mut spans: MultiSpan = cause. span . into ( ) ;
664
- spans. push_span_label (
665
- cause. span ,
666
- "unsatisfied trait bound introduced here" ,
667
- ) ;
668
- spans
666
+ let entry = spanned_predicates. entry ( self_ty. span ) ;
667
+ let entry = entry. or_insert_with ( || {
668
+ ( FxHashSet :: default ( ) , FxHashSet :: default ( ) , Vec :: new ( ) )
669
+ } ) ;
670
+ entry. 2 . push ( p) ;
671
+ if cause. span != * item_span {
672
+ entry. 0 . insert ( cause. span ) ;
673
+ entry. 1 . insert ( ( cause. span , "unsatisfied trait bound introduced here" ) ) ;
669
674
} else {
670
- let mut spans = Vec :: with_capacity ( 2 ) ;
671
675
if let Some ( trait_ref) = of_trait {
672
- spans . push ( trait_ref. path . span ) ;
676
+ entry . 0 . insert ( trait_ref. path . span ) ;
673
677
}
674
- spans. push ( self_ty. span ) ;
675
- spans. into ( )
678
+ entry. 0 . insert ( self_ty. span ) ;
676
679
} ;
677
680
if let Some ( trait_ref) = of_trait {
678
- spans . push_span_label ( trait_ref. path . span , "" ) ;
681
+ entry . 1 . insert ( ( trait_ref. path . span , "" ) ) ;
679
682
}
680
- spans. push_span_label ( self_ty. span , "" ) ;
681
-
682
- let entry = spanned_predicates. entry ( spans) ;
683
- entry. or_insert_with ( || Vec :: new ( ) ) . push ( p) ;
683
+ entry. 1 . insert ( ( self_ty. span , "" ) ) ;
684
684
}
685
685
Some ( Node :: Item ( hir:: Item {
686
686
kind : hir:: ItemKind :: Trait ( rustc_ast:: ast:: IsAuto :: Yes , ..) ,
@@ -697,8 +697,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
697
697
}
698
698
}
699
699
let mut spanned_predicates: Vec < _ > = spanned_predicates. into_iter ( ) . collect ( ) ;
700
- spanned_predicates. sort_by_key ( |( span, _) | span. primary_span ( ) ) ;
701
- for ( span , predicates) in spanned_predicates {
700
+ spanned_predicates. sort_by_key ( |( span, _) | * span) ;
701
+ for ( _ , ( primary_spans , span_labels , predicates) ) in spanned_predicates {
702
702
let mut preds: Vec < _ > = predicates
703
703
. iter ( )
704
704
. filter_map ( |pred| format_pred ( * * pred) )
@@ -711,6 +711,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711
711
} else {
712
712
format ! ( "the following trait bounds were not satisfied:\n {}" , preds. join( "\n " ) , )
713
713
} ;
714
+ let mut span: MultiSpan = primary_spans. into_iter ( ) . collect :: < Vec < _ > > ( ) . into ( ) ;
715
+ for ( sp, label) in span_labels {
716
+ span. push_span_label ( sp, label) ;
717
+ }
714
718
err. span_note ( span, & msg) ;
715
719
unsatisfied_bounds = true ;
716
720
}
0 commit comments