@@ -14,12 +14,12 @@ use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem
14
14
use rustc_attr as attr;
15
15
use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
16
16
use 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 } ;
19
19
use rustc_parse:: validate_attr;
20
20
use rustc_session:: parse:: feature_err;
21
21
use rustc_session:: Session ;
22
- use rustc_span:: edition:: { Edition , ALL_EDITIONS } ;
22
+ use rustc_span:: edition:: ALL_EDITIONS ;
23
23
use rustc_span:: symbol:: { sym, Symbol } ;
24
24
use rustc_span:: Span ;
25
25
use thin_vec:: ThinVec ;
@@ -36,16 +36,6 @@ pub struct StripUnconfigured<'a> {
36
36
}
37
37
38
38
pub 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
-
49
39
fn feature_list ( attr : & Attribute ) -> ThinVec < ast:: NestedMetaItem > {
50
40
if attr. has_name ( sym:: feature)
51
41
&& let Some ( list) = attr. meta_item_list ( )
@@ -83,11 +73,13 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
83
73
// Enable edition-dependent features based on `features_edition`.
84
74
// - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
85
75
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
+ }
91
83
}
92
84
93
85
// Process all features declared in the code.
@@ -147,19 +139,17 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
147
139
}
148
140
149
141
// 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 ;
158
148
}
159
149
160
150
// 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 ) ) ;
163
153
features. set_declared_lang_feature ( name, mi. span ( ) , since) ;
164
154
continue ;
165
155
}
@@ -175,8 +165,8 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
175
165
}
176
166
177
167
// 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) ;
180
170
features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
181
171
continue ;
182
172
}
0 commit comments