@@ -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 } ;
17
+ use rustc_feature:: Features ;
18
18
use rustc_feature:: { ACCEPTED_FEATURES , ACTIVE_FEATURES , REMOVED_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) && let Some ( list) = attr. meta_item_list ( ) {
51
41
list
@@ -79,11 +69,13 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
79
69
// Enable edition-dependent features based on `features_edition`.
80
70
// - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
81
71
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
+ }
87
79
}
88
80
89
81
// Process all features declared in the code.
@@ -143,19 +135,17 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
143
135
}
144
136
145
137
// 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 ;
154
144
}
155
145
156
146
// 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 ) ) ;
159
149
features. set_declared_lang_feature ( name, mi. span ( ) , since) ;
160
150
continue ;
161
151
}
@@ -171,8 +161,8 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
171
161
}
172
162
173
163
// 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) ;
176
166
features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
177
167
continue ;
178
168
}
0 commit comments