@@ -14,12 +14,12 @@ use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem
1414use rustc_attr as attr;
1515use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
1616use rustc_data_structures:: fx:: FxHashSet ;
17- use rustc_feature:: { Feature , Features , State as FeatureState } ;
17+ use rustc_feature:: Features ;
1818use rustc_feature:: { ACCEPTED_FEATURES , ACTIVE_FEATURES , REMOVED_FEATURES } ;
1919use rustc_parse:: validate_attr;
2020use rustc_session:: parse:: feature_err;
2121use rustc_session:: Session ;
22- use rustc_span:: edition:: { Edition , ALL_EDITIONS } ;
22+ use rustc_span:: edition:: ALL_EDITIONS ;
2323use rustc_span:: symbol:: { sym, Symbol } ;
2424use rustc_span:: Span ;
2525use thin_vec:: ThinVec ;
@@ -36,16 +36,6 @@ pub struct StripUnconfigured<'a> {
3636}
3737
3838pub fn features ( sess : & Session , krate_attrs : & [ Attribute ] ) -> Features {
39- fn active_features_up_to ( edition : Edition ) -> impl Iterator < Item = & ' static Feature > {
40- ACTIVE_FEATURES . iter ( ) . filter ( move |feature| {
41- if let Some ( feature_edition) = feature. edition {
42- feature_edition <= edition
43- } else {
44- false
45- }
46- } )
47- }
48-
4939 fn feature_list ( attr : & Attribute ) -> ThinVec < ast:: NestedMetaItem > {
5040 if attr. has_name ( sym:: feature) && let Some ( list) = attr. meta_item_list ( ) {
5141 list
@@ -79,11 +69,13 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
7969 // Enable edition-dependent features based on `features_edition`.
8070 // - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
8171 let mut edition_enabled_features = FxHashSet :: default ( ) ;
82- for feature in active_features_up_to ( features_edition) {
83- // FIXME(Manishearth) there is currently no way to set lib features by
84- // edition.
85- edition_enabled_features. insert ( feature. name ) ;
86- feature. set ( & mut features) ;
72+ for f in ACTIVE_FEATURES {
73+ if let Some ( edition) = f. feature . edition && edition <= features_edition {
74+ // FIXME(Manishearth) there is currently no way to set lib features by
75+ // edition.
76+ edition_enabled_features. insert ( f. feature . name ) ;
77+ ( f. set_enabled ) ( & mut features) ;
78+ }
8779 }
8880
8981 // Process all features declared in the code.
@@ -143,19 +135,17 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
143135 }
144136
145137 // If the declared feature has been removed, issue an error.
146- if let Some ( Feature { state, .. } ) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
147- if let FeatureState :: Removed { reason } = state {
148- sess. emit_err ( FeatureRemoved {
149- span : mi. span ( ) ,
150- reason : reason. map ( |reason| FeatureRemovedReason { reason } ) ,
151- } ) ;
152- continue ;
153- }
138+ if let Some ( f) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
139+ sess. emit_err ( FeatureRemoved {
140+ span : mi. span ( ) ,
141+ reason : f. reason . map ( |reason| FeatureRemovedReason { reason } ) ,
142+ } ) ;
143+ continue ;
154144 }
155145
156146 // If the declared feature is stable, record it.
157- if let Some ( Feature { since , .. } ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
158- let since = Some ( Symbol :: intern ( since) ) ;
147+ if let Some ( f ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
148+ let since = Some ( Symbol :: intern ( f . since ) ) ;
159149 features. set_declared_lang_feature ( name, mi. span ( ) , since) ;
160150 continue ;
161151 }
@@ -171,8 +161,8 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
171161 }
172162
173163 // If the declared feature is unstable, record it.
174- if let Some ( f) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. name ) {
175- f . set ( & mut features) ;
164+ if let Some ( f) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
165+ ( f . set_enabled ) ( & mut features) ;
176166 features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
177167 continue ;
178168 }
0 commit comments