@@ -10,8 +10,8 @@ use rustc_infer::traits::{
1010 FromSolverError , PredicateObligation , PredicateObligations , TraitEngine ,
1111} ;
1212use rustc_middle:: ty:: {
13- self , DelayedSet , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor ,
14- TypingMode ,
13+ self , DelayedSet , Ty , TyCtxt , TyVid , TypeSuperVisitable , TypeVisitable , TypeVisitableExt ,
14+ TypeVisitor , TypingMode ,
1515} ;
1616use rustc_next_trait_solver:: delegate:: SolverDelegate as _;
1717use rustc_next_trait_solver:: solve:: {
@@ -85,8 +85,27 @@ impl<'tcx> ObligationStorage<'tcx> {
8585 obligations. extend ( self . overflowed . iter ( ) . cloned ( ) ) ;
8686 obligations
8787 }
88+ fn clone_pending_potentially_referencing_sub_root (
89+ & self ,
90+ vid : TyVid ,
91+ ) -> PredicateObligations < ' tcx > {
92+ let mut obligations: PredicateObligations < ' tcx > = self
93+ . pending
94+ . iter ( )
95+ . filter ( |( _, stalled_on) | {
96+ if let Some ( stalled_on) = stalled_on {
97+ stalled_on. sub_roots . iter ( ) . any ( |& r| r == vid)
98+ } else {
99+ true
100+ }
101+ } )
102+ . map ( |( o, _) | o. clone ( ) )
103+ . collect ( ) ;
104+ obligations. extend ( self . overflowed . iter ( ) . cloned ( ) ) ;
105+ obligations
106+ }
88107
89- fn drain_pending (
108+ fn drain_pending_ignoring_overflowed (
90109 & mut self ,
91110 cond : impl Fn ( & PredicateObligation < ' tcx > ) -> bool ,
92111 ) -> PendingObligations < ' tcx > {
@@ -184,7 +203,9 @@ where
184203 let mut errors = Vec :: new ( ) ;
185204 loop {
186205 let mut any_changed = false ;
187- for ( mut obligation, stalled_on) in self . obligations . drain_pending ( |_| true ) {
206+ for ( mut obligation, stalled_on) in
207+ self . obligations . drain_pending_ignoring_overflowed ( |_| true )
208+ {
188209 if !infcx. tcx . recursion_limit ( ) . value_within_limit ( obligation. recursion_depth ) {
189210 self . obligations . on_fulfillment_overflow ( infcx) ;
190211 // Only return true errors that we have accumulated while processing.
@@ -277,6 +298,12 @@ where
277298 fn pending_obligations ( & self ) -> PredicateObligations < ' tcx > {
278299 self . obligations . clone_pending ( )
279300 }
301+ fn pending_obligations_potentially_referencing_sub_root (
302+ & self ,
303+ vid : ty:: TyVid ,
304+ ) -> PredicateObligations < ' tcx > {
305+ self . obligations . clone_pending_potentially_referencing_sub_root ( vid)
306+ }
280307
281308 fn drain_stalled_obligations_for_coroutines (
282309 & mut self ,
@@ -297,7 +324,7 @@ where
297324 }
298325
299326 self . obligations
300- . drain_pending ( |obl| {
327+ . drain_pending_ignoring_overflowed ( |obl| {
301328 infcx. probe ( |_| {
302329 infcx
303330 . visit_proof_tree (
0 commit comments