1
1
//! Conditional compilation stripping.
2
2
3
3
use crate :: errors:: {
4
- FeatureIncludedInEdition , FeatureNotAllowed , FeatureRemoved , FeatureRemovedReason , InvalidCfg ,
5
- MalformedFeatureAttribute , MalformedFeatureAttributeHelp , RemoveExprNotSupported ,
4
+ FeatureNotAllowed , FeatureRemoved , FeatureRemovedReason , InvalidCfg , MalformedFeatureAttribute ,
5
+ MalformedFeatureAttributeHelp , RemoveExprNotSupported ,
6
6
} ;
7
7
use rustc_ast:: ptr:: P ;
8
8
use rustc_ast:: token:: { Delimiter , Token , TokenKind } ;
@@ -13,13 +13,11 @@ use rustc_ast::NodeId;
13
13
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
- use rustc_data_structures:: fx:: FxHashSet ;
17
16
use rustc_feature:: Features ;
18
17
use rustc_feature:: { ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_FEATURES } ;
19
18
use rustc_parse:: validate_attr;
20
19
use rustc_session:: parse:: feature_err;
21
20
use rustc_session:: Session ;
22
- use rustc_span:: edition:: ALL_EDITIONS ;
23
21
use rustc_span:: symbol:: { sym, Symbol } ;
24
22
use rustc_span:: Span ;
25
23
use thin_vec:: ThinVec ;
@@ -48,42 +46,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
48
46
49
47
let mut features = Features :: default ( ) ;
50
48
51
- // The edition from `--edition`.
52
- let crate_edition = sess. edition ( ) ;
53
-
54
- // The maximum of (a) the edition from `--edition` and (b) any edition
55
- // umbrella feature-gates declared in the code.
56
- // - E.g. if `crate_edition` is 2015 but `rust_2018_preview` is present,
57
- // `feature_edition` is 2018
58
- let mut features_edition = crate_edition;
59
- for attr in krate_attrs {
60
- for mi in feature_list ( attr) {
61
- if mi. is_word ( ) {
62
- let name = mi. name_or_empty ( ) ;
63
- let edition = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) . copied ( ) ;
64
- if let Some ( edition) = edition
65
- && edition > features_edition
66
- {
67
- features_edition = edition;
68
- }
69
- }
70
- }
71
- }
72
-
73
- // Enable edition-dependent features based on `features_edition`.
74
- // - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
75
- let mut edition_enabled_features = FxHashSet :: default ( ) ;
76
- for f in UNSTABLE_FEATURES {
77
- if let Some ( edition) = f. feature . edition
78
- && edition <= features_edition
79
- {
80
- // FIXME(Manishearth) there is currently no way to set lib features by
81
- // edition.
82
- edition_enabled_features. insert ( f. feature . name ) ;
83
- ( f. set_enabled ) ( & mut features) ;
84
- }
85
- }
86
-
87
49
// Process all features declared in the code.
88
50
for attr in krate_attrs {
89
51
for mi in feature_list ( attr) {
@@ -108,38 +70,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
108
70
}
109
71
} ;
110
72
111
- // If the declared feature is an edition umbrella feature-gate,
112
- // warn if it was redundant w.r.t. `crate_edition`.
113
- // - E.g. warn if `rust_2018_preview` is declared when
114
- // `crate_edition` is 2018
115
- // - E.g. don't warn if `rust_2018_preview` is declared when
116
- // `crate_edition` is 2015.
117
- if let Some ( & edition) = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) {
118
- if edition <= crate_edition {
119
- sess. emit_warning ( FeatureIncludedInEdition {
120
- span : mi. span ( ) ,
121
- feature : name,
122
- edition,
123
- } ) ;
124
- }
125
- features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
126
- continue ;
127
- }
128
-
129
- // If the declared feature is edition-dependent and was already
130
- // enabled due to `feature_edition`, give a warning.
131
- // - E.g. warn if `test_2018_feature` is declared when
132
- // `feature_edition` is 2018 or higher.
133
- if edition_enabled_features. contains ( & name) {
134
- sess. emit_warning ( FeatureIncludedInEdition {
135
- span : mi. span ( ) ,
136
- feature : name,
137
- edition : features_edition,
138
- } ) ;
139
- features. set_declared_lang_feature ( name, mi. span ( ) , None ) ;
140
- continue ;
141
- }
142
-
143
73
// If the declared feature has been removed, issue an error.
144
74
if let Some ( f) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
145
75
sess. emit_err ( FeatureRemoved {
0 commit comments