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 ;
@@ -627,6 +627,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
627627}
628628
629629struct AmbiguityCausesVisitor < ' a , ' tcx > {
630+ cache : FxHashSet < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
630631 causes : & ' a mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
631632}
632633
@@ -636,6 +637,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
636637 }
637638
638639 fn visit_goal ( & mut self , goal : & InspectGoal < ' _ , ' tcx > ) {
640+ if !self . cache . insert ( goal. goal ( ) ) {
641+ return ;
642+ }
643+
639644 let infcx = goal. infcx ( ) ;
640645 for cand in goal. candidates ( ) {
641646 cand. visit_nested_in_probe ( self ) ;
@@ -760,5 +765,10 @@ fn search_ambiguity_causes<'tcx>(
760765 goal : Goal < ' tcx , ty:: Predicate < ' tcx > > ,
761766 causes : & mut FxIndexSet < IntercrateAmbiguityCause < ' tcx > > ,
762767) {
763- infcx. probe ( |_| infcx. visit_proof_tree ( goal, & mut AmbiguityCausesVisitor { causes } ) ) ;
768+ infcx. probe ( |_| {
769+ infcx. visit_proof_tree ( goal, & mut AmbiguityCausesVisitor {
770+ cache : Default :: default ( ) ,
771+ causes,
772+ } )
773+ } ) ;
764774}
0 commit comments