@@ -85,19 +85,20 @@ mod graphviz;
8585#[ cfg( test) ]
8686mod tests;
8787
88- pub trait ForestObligation : Clone + Debug {
89- type Predicate : Clone + hash:: Hash + Eq + Debug ;
88+ pub trait ForestObligation : Clone + Debug {
89+ type Predicate : Clone + hash:: Hash + Eq + Debug ;
9090
9191 fn as_predicate ( & self ) -> & Self :: Predicate ;
9292}
9393
9494pub trait ObligationProcessor {
95- type Obligation : ForestObligation ;
96- type Error : Debug ;
95+ type Obligation : ForestObligation ;
96+ type Error : Debug ;
9797
98- fn process_obligation ( & mut self ,
99- obligation : & mut Self :: Obligation )
100- -> ProcessResult < Self :: Obligation , Self :: Error > ;
98+ fn process_obligation (
99+ & mut self ,
100+ obligation : & mut Self :: Obligation ,
101+ ) -> ProcessResult < Self :: Obligation , Self :: Error > ;
101102
102103 /// As we do the cycle check, we invoke this callback when we
103104 /// encounter an actual cycle. `cycle` is an iterator that starts
@@ -107,10 +108,9 @@ pub trait ObligationProcessor {
107108 /// In other words, if we had O1 which required O2 which required
108109 /// O3 which required O1, we would give an iterator yielding O1,
109110 /// O2, O3 (O1 is not yielded twice).
110- fn process_backedge < ' c , I > ( & mut self ,
111- cycle : I ,
112- _marker : PhantomData < & ' c Self :: Obligation > )
113- where I : Clone + Iterator < Item =& ' c Self :: Obligation > ;
111+ fn process_backedge < ' c , I > ( & mut self , cycle : I , _marker : PhantomData < & ' c Self :: Obligation > )
112+ where
113+ I : Clone + Iterator < Item = & ' c Self :: Obligation > ;
114114}
115115
116116/// The result type used by `process_obligation`.
@@ -185,20 +185,11 @@ struct Node<O> {
185185}
186186
187187impl < O > Node < O > {
188- fn new (
189- parent : Option < usize > ,
190- obligation : O ,
191- obligation_tree_id : ObligationTreeId
192- ) -> Node < O > {
188+ fn new ( parent : Option < usize > , obligation : O , obligation_tree_id : ObligationTreeId ) -> Node < O > {
193189 Node {
194190 obligation,
195191 state : Cell :: new ( NodeState :: Pending ) ,
196- dependents :
197- if let Some ( parent_index) = parent {
198- vec ! [ parent_index]
199- } else {
200- vec ! [ ]
201- } ,
192+ dependents : if let Some ( parent_index) = parent { vec ! [ parent_index] } else { vec ! [ ] } ,
202193 has_parent : parent. is_some ( ) ,
203194 obligation_tree_id,
204195 }
@@ -339,24 +330,20 @@ impl<O: ForestObligation> ObligationForest<O> {
339330 node. dependents . push ( parent_index) ;
340331 }
341332 }
342- if let NodeState :: Error = node. state . get ( ) {
343- Err ( ( ) )
344- } else {
345- Ok ( ( ) )
346- }
333+ if let NodeState :: Error = node. state . get ( ) { Err ( ( ) ) } else { Ok ( ( ) ) }
347334 }
348335 Entry :: Vacant ( v) => {
349336 let obligation_tree_id = match parent {
350337 Some ( parent_index) => self . nodes [ parent_index] . obligation_tree_id ,
351338 None => self . obligation_tree_id_generator . next ( ) . unwrap ( ) ,
352339 } ;
353340
354- let already_failed =
355- parent . is_some ( )
356- && self . error_cache
357- . get ( & obligation_tree_id)
358- . map ( |errors| errors. contains ( obligation. as_predicate ( ) ) )
359- . unwrap_or ( false ) ;
341+ let already_failed = parent . is_some ( )
342+ && self
343+ . error_cache
344+ . get ( & obligation_tree_id)
345+ . map ( |errors| errors. contains ( obligation. as_predicate ( ) ) )
346+ . unwrap_or ( false ) ;
360347
361348 if already_failed {
362349 Err ( ( ) )
@@ -372,14 +359,12 @@ impl<O: ForestObligation> ObligationForest<O> {
372359
373360 /// Converts all remaining obligations to the given error.
374361 pub fn to_errors < E : Clone > ( & mut self , error : E ) -> Vec < Error < O , E > > {
375- let errors = self . nodes . iter ( ) . enumerate ( )
362+ let errors = self
363+ . nodes
364+ . iter ( )
365+ . enumerate ( )
376366 . filter ( |( _index, node) | node. state . get ( ) == NodeState :: Pending )
377- . map ( |( index, _node) | {
378- Error {
379- error : error. clone ( ) ,
380- backtrace : self . error_at ( index) ,
381- }
382- } )
367+ . map ( |( index, _node) | Error { error : error. clone ( ) , backtrace : self . error_at ( index) } )
383368 . collect ( ) ;
384369
385370 let successful_obligations = self . compress ( DoCompleted :: Yes ) ;
@@ -389,9 +374,11 @@ impl<O: ForestObligation> ObligationForest<O> {
389374
390375 /// Returns the set of obligations that are in a pending state.
391376 pub fn map_pending_obligations < P , F > ( & self , f : F ) -> Vec < P >
392- where F : Fn ( & O ) -> P
377+ where
378+ F : Fn ( & O ) -> P ,
393379 {
394- self . nodes . iter ( )
380+ self . nodes
381+ . iter ( )
395382 . filter ( |node| node. state . get ( ) == NodeState :: Pending )
396383 . map ( |node| f ( & node. obligation ) )
397384 . collect ( )
@@ -421,9 +408,13 @@ impl<O: ForestObligation> ObligationForest<O> {
421408 /// be called in a loop until `outcome.stalled` is false.
422409 ///
423410 /// This _cannot_ be unrolled (presently, at least).
424- pub fn process_obligations < P > ( & mut self , processor : & mut P , do_completed : DoCompleted )
425- -> Outcome < O , P :: Error >
426- where P : ObligationProcessor < Obligation =O >
411+ pub fn process_obligations < P > (
412+ & mut self ,
413+ processor : & mut P ,
414+ do_completed : DoCompleted ,
415+ ) -> Outcome < O , P :: Error >
416+ where
417+ P : ObligationProcessor < Obligation = O > ,
427418 {
428419 self . gen += 1 ;
429420
@@ -462,10 +453,7 @@ impl<O: ForestObligation> ObligationForest<O> {
462453 node. state . set ( NodeState :: Success ( Self :: not_waiting ( ) ) ) ;
463454
464455 for child in children {
465- let st = self . register_obligation_at (
466- child,
467- Some ( index)
468- ) ;
456+ let st = self . register_obligation_at ( child, Some ( index) ) ;
469457 if let Err ( ( ) ) = st {
470458 // Error already reported - propagate it
471459 // to our node.
@@ -475,10 +463,7 @@ impl<O: ForestObligation> ObligationForest<O> {
475463 }
476464 ProcessResult :: Error ( err) => {
477465 stalled = false ;
478- errors. push ( Error {
479- error : err,
480- backtrace : self . error_at ( index) ,
481- } ) ;
466+ errors. push ( Error { error : err, backtrace : self . error_at ( index) } ) ;
482467 }
483468 }
484469 index += 1 ;
@@ -498,11 +483,7 @@ impl<O: ForestObligation> ObligationForest<O> {
498483 self . process_cycles ( processor) ;
499484 let completed = self . compress ( do_completed) ;
500485
501- Outcome {
502- completed,
503- errors,
504- stalled,
505- }
486+ Outcome { completed, errors, stalled }
506487 }
507488
508489 /// Returns a vector of obligations for `p` and all of its
@@ -574,7 +555,8 @@ impl<O: ForestObligation> ObligationForest<O> {
574555 /// Report cycles between all `Success` nodes that aren't still waiting.
575556 /// This must be called after `mark_still_waiting_nodes`.
576557 fn process_cycles < P > ( & self , processor : & mut P )
577- where P : ObligationProcessor < Obligation =O >
558+ where
559+ P : ObligationProcessor < Obligation = O > ,
578560 {
579561 let mut stack = vec ! [ ] ;
580562
@@ -592,9 +574,14 @@ impl<O: ForestObligation> ObligationForest<O> {
592574 debug_assert ! ( stack. is_empty( ) ) ;
593575 }
594576
595- fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > , processor : & mut P , min_index : usize ,
596- index : usize )
597- where P : ObligationProcessor < Obligation =O >
577+ fn find_cycles_from_node < P > (
578+ & self ,
579+ stack : & mut Vec < usize > ,
580+ processor : & mut P ,
581+ min_index : usize ,
582+ index : usize ,
583+ ) where
584+ P : ObligationProcessor < Obligation = O > ,
598585 {
599586 let node = & self . nodes [ index] ;
600587 if let NodeState :: Success ( waiting) = node. state . get ( ) {
@@ -614,7 +601,7 @@ impl<O: ForestObligation> ObligationForest<O> {
614601 // Cycle detected.
615602 processor. process_backedge (
616603 stack[ rpos..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
617- PhantomData
604+ PhantomData ,
618605 ) ;
619606 }
620607 }
@@ -697,11 +684,7 @@ impl<O: ForestObligation> ObligationForest<O> {
697684 node_rewrites. truncate ( 0 ) ;
698685 self . node_rewrites . replace ( node_rewrites) ;
699686
700- if do_completed == DoCompleted :: Yes {
701- Some ( removed_success_obligations)
702- } else {
703- None
704- }
687+ if do_completed == DoCompleted :: Yes { Some ( removed_success_obligations) } else { None }
705688 }
706689
707690 fn apply_rewrites ( & mut self , node_rewrites : & [ usize ] ) {
0 commit comments