@@ -595,11 +595,12 @@ impl RemainingCandidates {
595
595
///
596
596
/// If all dependencies can be activated and resolved to a version in the
597
597
/// dependency graph, cx.resolve is returned.
598
- fn activate_deps_loop < ' a > ( mut cx : Context < ' a > ,
599
- registry : & mut Registry ,
600
- summaries : & [ ( Summary , Method ) ] ,
601
- config : Option < & Config > )
602
- -> CargoResult < Context < ' a > > {
598
+ fn activate_deps_loop < ' a > (
599
+ mut cx : Context < ' a > ,
600
+ registry : & mut Registry ,
601
+ summaries : & [ ( Summary , Method ) ] ,
602
+ config : Option < & Config > ,
603
+ ) -> CargoResult < Context < ' a > > {
603
604
// Note that a `BinaryHeap` is used for the remaining dependencies that need
604
605
// activation. This heap is sorted such that the "largest value" is the most
605
606
// constrained dependency, or the one with the least candidates.
@@ -611,7 +612,10 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
611
612
let mut remaining_deps = BinaryHeap :: new ( ) ;
612
613
for & ( ref summary, ref method) in summaries {
613
614
debug ! ( "initial activation: {}" , summary. package_id( ) ) ;
614
- let candidate = Candidate { summary : summary. clone ( ) , replace : None } ;
615
+ let candidate = Candidate {
616
+ summary : summary. clone ( ) ,
617
+ replace : None ,
618
+ } ;
615
619
let res = activate ( & mut cx, registry, None , candidate, method) ?;
616
620
if let Some ( ( frame, _) ) = res {
617
621
remaining_deps. push ( frame) ;
@@ -638,7 +642,6 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
638
642
// backtracking states where if we hit an error we can return to in order to
639
643
// attempt to continue resolving.
640
644
while let Some ( mut deps_frame) = remaining_deps. pop ( ) {
641
-
642
645
// If we spend a lot of time here (we shouldn't in most cases) then give
643
646
// a bit of a visual indicator as to what we're doing. Only enable this
644
647
// when stderr is a tty (a human is likely to be watching) to ensure we
@@ -650,10 +653,8 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
650
653
// to amortize the cost of the current time lookup.
651
654
ticks += 1 ;
652
655
if let Some ( config) = config {
653
- if config. shell ( ) . is_err_tty ( ) &&
654
- !printed &&
655
- ticks % 1000 == 0 &&
656
- start. elapsed ( ) - deps_time > time_to_print
656
+ if config. shell ( ) . is_err_tty ( ) && !printed && ticks % 1000 == 0
657
+ && start. elapsed ( ) - deps_time > time_to_print
657
658
{
658
659
printed = true ;
659
660
config. shell ( ) . status ( "Resolving" , "dependency graph..." ) ?;
@@ -688,54 +689,55 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
688
689
// This means that we're going to attempt to activate each candidate in
689
690
// turn. We could possibly fail to activate each candidate, so we try
690
691
// each one in turn.
691
- let candidate = match next {
692
- Ok ( ( candidate, has_another) ) => {
693
- // We have a candidate. Add an entry to the `backtrack_stack` so
694
- // we can try the next one if this one fails.
695
- if has_another {
696
- backtrack_stack. push ( BacktrackFrame {
697
- cur,
698
- context_backup : Context :: clone ( & cx) ,
699
- deps_backup : <BinaryHeap < DepsFrame > >:: clone ( & remaining_deps) ,
700
- remaining_candidates,
701
- parent : Summary :: clone ( & parent) ,
702
- dep : Dependency :: clone ( & dep) ,
703
- features : Rc :: clone ( & features) ,
704
- } ) ;
705
- }
706
- candidate
707
- }
708
- Err ( mut conflicting) => {
709
- // This dependency has no valid candidate. Backtrack until we
710
- // find a dependency that does have a candidate to try, and try
711
- // to activate that one. This resets the `remaining_deps` to
712
- // their state at the found level of the `backtrack_stack`.
713
- trace ! ( "{}[{}]>{} -- no candidates" , parent. name( ) , cur,
714
- dep. name( ) ) ;
715
- match find_candidate ( & mut backtrack_stack,
716
- & mut cx,
717
- & mut remaining_deps,
718
- & mut parent,
719
- & mut cur,
720
- & mut dep,
721
- & mut features,
722
- & mut conflicting) {
723
- None => return Err ( activation_error ( & cx, registry, & parent,
724
- & dep,
725
- conflicting,
726
- & candidates, config) ) ,
727
- Some ( candidate) => candidate,
728
- }
729
- }
730
- } ;
692
+ let ( candidate, has_another) = next. or_else ( |mut conflicting| {
693
+ // This dependency has no valid candidate. Backtrack until we
694
+ // find a dependency that does have a candidate to try, and try
695
+ // to activate that one. This resets the `remaining_deps` to
696
+ // their state at the found level of the `backtrack_stack`.
697
+ trace ! ( "{}[{}]>{} -- no candidates" , parent. name( ) , cur, dep. name( ) ) ;
698
+ find_candidate (
699
+ & mut backtrack_stack,
700
+ & mut cx,
701
+ & mut remaining_deps,
702
+ & mut parent,
703
+ & mut cur,
704
+ & mut dep,
705
+ & mut features,
706
+ & mut remaining_candidates,
707
+ & mut conflicting,
708
+ ) . ok_or_else ( || {
709
+ activation_error (
710
+ & cx,
711
+ registry,
712
+ & parent,
713
+ & dep,
714
+ conflicting,
715
+ & candidates,
716
+ config,
717
+ )
718
+ } )
719
+ } ) ?;
720
+
721
+ // We have a candidate. Add an entry to the `backtrack_stack` so
722
+ // we can try the next one if this one fails.
723
+ if has_another {
724
+ backtrack_stack. push ( BacktrackFrame {
725
+ cur,
726
+ context_backup : Context :: clone ( & cx) ,
727
+ deps_backup : <BinaryHeap < DepsFrame > >:: clone ( & remaining_deps) ,
728
+ remaining_candidates,
729
+ parent : Summary :: clone ( & parent) ,
730
+ dep : Dependency :: clone ( & dep) ,
731
+ features : Rc :: clone ( & features) ,
732
+ } ) ;
733
+ }
731
734
732
735
let method = Method :: Required {
733
736
dev_deps : false ,
734
737
features : & features,
735
738
uses_default_features : dep. uses_default_features ( ) ,
736
739
} ;
737
- trace ! ( "{}[{}]>{} trying {}" , parent. name( ) , cur, dep. name( ) ,
738
- candidate. summary. version( ) ) ;
740
+ trace ! ( "{}[{}]>{} trying {}" , parent. name( ) , cur, dep. name( ) , candidate. summary. version( ) ) ;
739
741
let res = activate ( & mut cx, registry, Some ( & parent) , candidate, & method) ?;
740
742
if let Some ( ( frame, dur) ) = res {
741
743
remaining_deps. push ( frame) ;
@@ -765,8 +767,9 @@ fn find_candidate<'a>(
765
767
cur : & mut usize ,
766
768
dep : & mut Dependency ,
767
769
features : & mut Rc < Vec < String > > ,
770
+ remaining_candidates : & mut RemainingCandidates ,
768
771
conflicting_activations : & mut HashSet < PackageId > ,
769
- ) -> Option < Candidate > {
772
+ ) -> Option < ( Candidate , bool ) > {
770
773
while let Some ( mut frame) = backtrack_stack. pop ( ) {
771
774
let next= frame. remaining_candidates . next ( frame. context_backup . prev_active ( & frame. dep ) ) ;
772
775
if frame. context_backup . is_active ( parent. package_id ( ) )
@@ -778,16 +781,14 @@ fn find_candidate<'a>(
778
781
continue ;
779
782
}
780
783
if let Ok ( ( candidate, has_another) ) = next {
781
- if has_another {
782
- backtrack_stack. push ( frame. clone ( ) ) ;
783
- }
784
784
* cur = frame. cur ;
785
785
* cx = frame. context_backup ;
786
786
* remaining_deps = frame. deps_backup ;
787
787
* parent = frame. parent ;
788
788
* dep = frame. dep ;
789
789
* features = frame. features ;
790
- return Some ( candidate) ;
790
+ * remaining_candidates = frame. remaining_candidates ;
791
+ return Some ( ( candidate, has_another) ) ;
791
792
}
792
793
}
793
794
None
0 commit comments