@@ -584,15 +584,16 @@ impl<O: ForestObligation> ObligationForest<O> {
584584 // function call.
585585 if let NodeState :: Success ( waiting) = node. state . get ( ) {
586586 if !self . is_still_waiting ( waiting) {
587- self . find_cycles_from_node ( & mut stack, processor, index) ;
587+ self . find_cycles_from_node ( & mut stack, processor, index, index ) ;
588588 }
589589 }
590590 }
591591
592592 debug_assert ! ( stack. is_empty( ) ) ;
593593 }
594594
595- fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > , processor : & mut P , index : usize )
595+ fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > , processor : & mut P , min_index : usize ,
596+ index : usize )
596597 where P : ObligationProcessor < Obligation =O >
597598 {
598599 let node = & self . nodes [ index] ;
@@ -601,8 +602,11 @@ impl<O: ForestObligation> ObligationForest<O> {
601602 match stack. iter ( ) . rposition ( |& n| n == index) {
602603 None => {
603604 stack. push ( index) ;
604- for & index in node. dependents . iter ( ) {
605- self . find_cycles_from_node ( stack, processor, index) ;
605+ for & dep_index in node. dependents . iter ( ) {
606+ // The index check avoids re-considering a node.
607+ if dep_index >= min_index {
608+ self . find_cycles_from_node ( stack, processor, min_index, dep_index) ;
609+ }
606610 }
607611 stack. pop ( ) ;
608612 }
0 commit comments