@@ -732,13 +732,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
732732 }
733733 }
734734
735- for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
736- if let Some ( f_edition) = f_edition {
737- if f_edition <= crate_edition {
738- set ( & mut features, DUMMY_SP ) ;
739- edition_enabled_features. insert ( name, crate_edition) ;
740- }
741- }
735+ for feature in active_features_up_to ( crate_edition) {
736+ feature. set ( & mut features, DUMMY_SP ) ;
737+ edition_enabled_features. insert ( feature. name , crate_edition) ;
742738 }
743739
744740 // Process the edition umbrella feature-gates first, to ensure
@@ -760,20 +756,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
760756
761757 let name = mi. name_or_empty ( ) ;
762758
763- if let Some ( edition) = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) {
764- if * edition <= crate_edition {
759+ let edition = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) . copied ( ) ;
760+ if let Some ( edition) = edition {
761+ if edition <= crate_edition {
765762 continue ;
766763 }
767764
768- for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
769- if let Some ( f_edition) = f_edition {
770- if f_edition <= * edition {
771- // FIXME(Manishearth) there is currently no way to set
772- // lib features by edition
773- set ( & mut features, DUMMY_SP ) ;
774- edition_enabled_features. insert ( name, * edition) ;
775- }
776- }
765+ for feature in active_features_up_to ( edition) {
766+ // FIXME(Manishearth) there is currently no way to set
767+ // lib features by edition
768+ feature. set ( & mut features, DUMMY_SP ) ;
769+ edition_enabled_features. insert ( feature. name , edition) ;
777770 }
778771 }
779772 }
@@ -867,6 +860,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
867860 features
868861}
869862
863+ fn active_features_up_to ( edition : Edition ) -> impl Iterator < Item =& ' static Feature > {
864+ ACTIVE_FEATURES . iter ( )
865+ . filter ( move |feature| {
866+ if let Some ( feature_edition) = feature. edition {
867+ feature_edition <= edition
868+ } else {
869+ false
870+ }
871+ } )
872+ }
873+
870874pub fn check_crate ( krate : & ast:: Crate ,
871875 sess : & ParseSess ,
872876 features : & Features ,
0 commit comments