@@ -659,53 +659,41 @@ fn build_features(s: &Summary, method: &Method)
659
659
visited : & mut HashSet < String > ) -> CargoResult < ( ) > {
660
660
if feat. is_empty ( ) { return Ok ( ( ) ) }
661
661
662
- if !visited. insert ( feat. to_string ( ) ) {
663
- bail ! ( "Cyclic feature dependency: feature `{}` depends \
664
- on itself", feat)
665
- }
666
-
667
- used. insert ( feat. to_string ( ) ) ;
668
-
669
- // The lookup of here may fail if the feature corresponds to an optional
670
- // dependency. If that is the case, we simply enable the optional dependency.
671
- //
672
- // Otherwise, we check what other features the feature wants and recursively
673
- // add them.
674
- match s. features ( ) . get ( feat) {
675
- Some ( wanted_features) => {
676
- for entry in wanted_features {
677
- // If the entry is of the form `foo/bar`, then we just lookup package
678
- // `foo` and enable its feature `bar`. We also add `foo` to the used
679
- // set because `foo` might have been an optional dependency.
680
- //
681
- // Otherwise the entry refers to another feature of our current package,
682
- // so we recurse by calling add_feature again, which may end up enabling
683
- // more features or just enabling a dependency (remember, optional
684
- // dependencies create an implicit feature with the same name).
685
- let mut parts = entry. splitn ( 2 , '/' ) ;
686
- let feat_or_package = parts. next ( ) . unwrap ( ) ;
687
- match parts. next ( ) {
688
- Some ( feat) => {
689
- let package = feat_or_package;
690
- used. insert ( package. to_string ( ) ) ;
691
- deps. entry ( package. to_string ( ) )
692
- . or_insert ( Vec :: new ( ) )
693
- . push ( feat. to_string ( ) ) ;
694
- }
695
- None => {
696
- let feat = feat_or_package;
697
- try!( add_feature ( s, feat, deps, used, visited) ) ;
662
+ // If this feature is of the form `foo/bar`, then we just lookup package
663
+ // `foo` and enable its feature `bar`. Otherwise this feature is of the
664
+ // form `foo` and we need to recurse to enable the feature `foo` for our
665
+ // own package, which may end up enabling more features or just enabling
666
+ // a dependency.
667
+ let mut parts = feat. splitn ( 2 , '/' ) ;
668
+ let feat_or_package = parts. next ( ) . unwrap ( ) ;
669
+ match parts. next ( ) {
670
+ Some ( feat) => {
671
+ let package = feat_or_package;
672
+ used. insert ( package. to_string ( ) ) ;
673
+ deps. entry ( package. to_string ( ) )
674
+ . or_insert ( Vec :: new ( ) )
675
+ . push ( feat. to_string ( ) ) ;
676
+ }
677
+ None => {
678
+ let feat = feat_or_package;
679
+ if !visited. insert ( feat. to_string ( ) ) {
680
+ bail ! ( "Cyclic feature dependency: feature `{}` depends \
681
+ on itself", feat)
682
+ }
683
+ used. insert ( feat. to_string ( ) ) ;
684
+ match s. features ( ) . get ( feat) {
685
+ Some ( recursive) => {
686
+ for f in recursive {
687
+ try!( add_feature ( s, f, deps, used, visited) ) ;
698
688
}
699
689
}
690
+ None => {
691
+ deps. entry ( feat. to_string ( ) ) . or_insert ( Vec :: new ( ) ) ;
692
+ }
700
693
}
701
- }
702
- None => {
703
- deps. entry ( feat. to_string ( ) ) . or_insert ( Vec :: new ( ) ) ;
694
+ visited. remove ( & feat. to_string ( ) ) ;
704
695
}
705
696
}
706
-
707
- visited. remove ( & feat. to_string ( ) ) ;
708
-
709
697
Ok ( ( ) )
710
698
}
711
699
}
0 commit comments