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