66
77use std:: fmt:: Debug ;
88
9- use rustc_data_structures:: fx:: FxIndexSet ;
9+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
1010use rustc_errors:: { Diag , EmissionGuarantee } ;
1111use rustc_hir:: def:: DefKind ;
1212use rustc_hir:: def_id:: DefId ;
@@ -626,6 +626,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
626626}
627627
628628struct AmbiguityCausesVisitor < ' a , ' tcx > {
629+ cache : FxHashSet < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
629630 causes : & ' a mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
630631}
631632
@@ -635,6 +636,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
635636 }
636637
637638 fn visit_goal ( & mut self , goal : & InspectGoal < ' _ , ' tcx > ) {
639+ if !self . cache . insert ( goal. goal ( ) ) {
640+ return ;
641+ }
642+
638643 let infcx = goal. infcx ( ) ;
639644 for cand in goal. candidates ( ) {
640645 cand. visit_nested_in_probe ( self ) ;
@@ -759,5 +764,10 @@ fn search_ambiguity_causes<'tcx>(
759764 goal : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
760765 causes : & mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
761766) {
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+ } ) ;
763773}
0 commit comments