@@ -85,19 +85,20 @@ mod graphviz;
85
85
#[ cfg( test) ]
86
86
mod tests;
87
87
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 ;
90
90
91
91
fn as_predicate ( & self ) -> & Self :: Predicate ;
92
92
}
93
93
94
94
pub trait ObligationProcessor {
95
- type Obligation : ForestObligation ;
96
- type Error : Debug ;
95
+ type Obligation : ForestObligation ;
96
+ type Error : Debug ;
97
97
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 > ;
101
102
102
103
/// As we do the cycle check, we invoke this callback when we
103
104
/// encounter an actual cycle. `cycle` is an iterator that starts
@@ -107,10 +108,9 @@ pub trait ObligationProcessor {
107
108
/// In other words, if we had O1 which required O2 which required
108
109
/// O3 which required O1, we would give an iterator yielding O1,
109
110
/// 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 > ;
114
114
}
115
115
116
116
/// The result type used by `process_obligation`.
@@ -185,20 +185,11 @@ struct Node<O> {
185
185
}
186
186
187
187
impl < 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 > {
193
189
Node {
194
190
obligation,
195
191
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 ! [ ] } ,
202
193
has_parent : parent. is_some ( ) ,
203
194
obligation_tree_id,
204
195
}
@@ -339,24 +330,20 @@ impl<O: ForestObligation> ObligationForest<O> {
339
330
node. dependents . push ( parent_index) ;
340
331
}
341
332
}
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 ( ( ) ) }
347
334
}
348
335
Entry :: Vacant ( v) => {
349
336
let obligation_tree_id = match parent {
350
337
Some ( parent_index) => self . nodes [ parent_index] . obligation_tree_id ,
351
338
None => self . obligation_tree_id_generator . next ( ) . unwrap ( ) ,
352
339
} ;
353
340
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 ) ;
360
347
361
348
if already_failed {
362
349
Err ( ( ) )
@@ -372,14 +359,12 @@ impl<O: ForestObligation> ObligationForest<O> {
372
359
373
360
/// Converts all remaining obligations to the given error.
374
361
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 ( )
376
366
. 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) } )
383
368
. collect ( ) ;
384
369
385
370
let successful_obligations = self . compress ( DoCompleted :: Yes ) ;
@@ -389,9 +374,11 @@ impl<O: ForestObligation> ObligationForest<O> {
389
374
390
375
/// Returns the set of obligations that are in a pending state.
391
376
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 ,
393
379
{
394
- self . nodes . iter ( )
380
+ self . nodes
381
+ . iter ( )
395
382
. filter ( |node| node. state . get ( ) == NodeState :: Pending )
396
383
. map ( |node| f ( & node. obligation ) )
397
384
. collect ( )
@@ -421,9 +408,13 @@ impl<O: ForestObligation> ObligationForest<O> {
421
408
/// be called in a loop until `outcome.stalled` is false.
422
409
///
423
410
/// 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 > ,
427
418
{
428
419
self . gen += 1 ;
429
420
@@ -462,10 +453,7 @@ impl<O: ForestObligation> ObligationForest<O> {
462
453
node. state . set ( NodeState :: Success ( Self :: not_waiting ( ) ) ) ;
463
454
464
455
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) ) ;
469
457
if let Err ( ( ) ) = st {
470
458
// Error already reported - propagate it
471
459
// to our node.
@@ -475,10 +463,7 @@ impl<O: ForestObligation> ObligationForest<O> {
475
463
}
476
464
ProcessResult :: Error ( err) => {
477
465
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) } ) ;
482
467
}
483
468
}
484
469
index += 1 ;
@@ -498,11 +483,7 @@ impl<O: ForestObligation> ObligationForest<O> {
498
483
self . process_cycles ( processor) ;
499
484
let completed = self . compress ( do_completed) ;
500
485
501
- Outcome {
502
- completed,
503
- errors,
504
- stalled,
505
- }
486
+ Outcome { completed, errors, stalled }
506
487
}
507
488
508
489
/// Returns a vector of obligations for `p` and all of its
@@ -574,7 +555,8 @@ impl<O: ForestObligation> ObligationForest<O> {
574
555
/// Report cycles between all `Success` nodes that aren't still waiting.
575
556
/// This must be called after `mark_still_waiting_nodes`.
576
557
fn process_cycles < P > ( & self , processor : & mut P )
577
- where P : ObligationProcessor < Obligation =O >
558
+ where
559
+ P : ObligationProcessor < Obligation = O > ,
578
560
{
579
561
let mut stack = vec ! [ ] ;
580
562
@@ -592,9 +574,14 @@ impl<O: ForestObligation> ObligationForest<O> {
592
574
debug_assert ! ( stack. is_empty( ) ) ;
593
575
}
594
576
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 > ,
598
585
{
599
586
let node = & self . nodes [ index] ;
600
587
if let NodeState :: Success ( waiting) = node. state . get ( ) {
@@ -614,7 +601,7 @@ impl<O: ForestObligation> ObligationForest<O> {
614
601
// Cycle detected.
615
602
processor. process_backedge (
616
603
stack[ rpos..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
617
- PhantomData
604
+ PhantomData ,
618
605
) ;
619
606
}
620
607
}
@@ -697,11 +684,7 @@ impl<O: ForestObligation> ObligationForest<O> {
697
684
node_rewrites. truncate ( 0 ) ;
698
685
self . node_rewrites . replace ( node_rewrites) ;
699
686
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 }
705
688
}
706
689
707
690
fn apply_rewrites ( & mut self , node_rewrites : & [ usize ] ) {
0 commit comments