6
6
7
7
use std:: fmt:: Debug ;
8
8
9
- use rustc_data_structures:: fx:: FxIndexSet ;
9
+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
10
10
use rustc_errors:: { Diag , EmissionGuarantee } ;
11
11
use rustc_hir:: def:: DefKind ;
12
12
use rustc_hir:: def_id:: DefId ;
@@ -626,6 +626,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
626
626
}
627
627
628
628
struct AmbiguityCausesVisitor < ' a , ' tcx > {
629
+ cache : FxHashSet < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
629
630
causes : & ' a mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
630
631
}
631
632
@@ -635,6 +636,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
635
636
}
636
637
637
638
fn visit_goal ( & mut self , goal : & InspectGoal < ' _ , ' tcx > ) {
639
+ if !self . cache . insert ( goal. goal ( ) ) {
640
+ return ;
641
+ }
642
+
638
643
let infcx = goal. infcx ( ) ;
639
644
for cand in goal. candidates ( ) {
640
645
cand. visit_nested_in_probe ( self ) ;
@@ -759,5 +764,10 @@ fn search_ambiguity_causes<'tcx>(
759
764
goal : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
760
765
causes : & mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
761
766
) {
762
- infcx. probe ( |_| infcx. visit_proof_tree ( goal, & mut AmbiguityCausesVisitor { causes } ) ) ;
767
+ infcx. probe ( |_| {
768
+ infcx. visit_proof_tree ( goal, & mut AmbiguityCausesVisitor {
769
+ cache : Default :: default ( ) ,
770
+ causes,
771
+ } )
772
+ } ) ;
763
773
}
0 commit comments