@@ -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 } ;
18- use rustc_feature:: { ACCEPTED_FEATURES , ACTIVE_FEATURES , REMOVED_FEATURES } ;
17+ use rustc_feature:: Features ;
18+ use rustc_feature:: { ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_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)
5141 && let Some ( list) = attr. meta_item_list ( )
@@ -83,11 +73,13 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
8373 // Enable edition-dependent features based on `features_edition`.
8474 // - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
8575 let mut edition_enabled_features = FxHashSet :: default ( ) ;
86- for feature in active_features_up_to ( features_edition) {
87- // FIXME(Manishearth) there is currently no way to set lib features by
88- // edition.
89- edition_enabled_features. insert ( feature. name ) ;
90- feature. set ( & mut features) ;
76+ for f in UNSTABLE_FEATURES {
77+ if let Some ( edition) = f. feature . edition && edition <= features_edition {
78+ // FIXME(Manishearth) there is currently no way to set lib features by
79+ // edition.
80+ edition_enabled_features. insert ( f. feature . name ) ;
81+ ( f. set_enabled ) ( & mut features) ;
82+ }
9183 }
9284
9385 // Process all features declared in the code.
@@ -147,19 +139,17 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
147139 }
148140
149141 // If the declared feature has been removed, issue an error.
150- if let Some ( Feature { state, .. } ) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
151- if let FeatureState :: Removed { reason } = state {
152- sess. emit_err ( FeatureRemoved {
153- span : mi. span ( ) ,
154- reason : reason. map ( |reason| FeatureRemovedReason { reason } ) ,
155- } ) ;
156- continue ;
157- }
142+ if let Some ( f) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
143+ sess. emit_err ( FeatureRemoved {
144+ span : mi. span ( ) ,
145+ reason : f. reason . map ( |reason| FeatureRemovedReason { reason } ) ,
146+ } ) ;
147+ continue ;
158148 }
159149
160150 // If the declared feature is stable, record it.
161- if let Some ( Feature { since , .. } ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
162- let since = Some ( Symbol :: intern ( since) ) ;
151+ if let Some ( f ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
152+ let since = Some ( Symbol :: intern ( f . since ) ) ;
163153 features. set_declared_lang_feature ( name, mi. span ( ) , since) ;
164154 continue ;
165155 }
@@ -175,8 +165,8 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
175165 }
176166
177167 // If the declared feature is unstable, record it.
178- if let Some ( f) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. name ) {
179- f . set ( & mut features) ;
168+ if let Some ( f) = UNSTABLE_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
169+ ( f . set_enabled ) ( & mut features) ;
180170 features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
181171 continue ;
182172 }
0 commit comments