11//! Conditional compilation stripping.
22
33use crate :: errors:: {
4- FeatureIncludedInEdition , FeatureNotAllowed , FeatureRemoved , FeatureRemovedReason , InvalidCfg ,
5- MalformedFeatureAttribute , MalformedFeatureAttributeHelp , RemoveExprNotSupported ,
4+ FeatureNotAllowed , FeatureRemoved , FeatureRemovedReason , InvalidCfg , MalformedFeatureAttribute ,
5+ MalformedFeatureAttributeHelp , RemoveExprNotSupported ,
66} ;
77use rustc_ast:: ptr:: P ;
88use rustc_ast:: token:: { Delimiter , Token , TokenKind } ;
@@ -13,13 +13,11 @@ use rustc_ast::NodeId;
1313use rustc_ast:: { self as ast, AttrStyle , Attribute , HasAttrs , HasTokens , MetaItem } ;
1414use rustc_attr as attr;
1515use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
16- use rustc_data_structures:: fx:: FxHashSet ;
1716use rustc_feature:: Features ;
1817use rustc_feature:: { ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_FEATURES } ;
1918use rustc_parse:: validate_attr;
2019use rustc_session:: parse:: feature_err;
2120use rustc_session:: Session ;
22- use rustc_span:: edition:: ALL_EDITIONS ;
2321use rustc_span:: symbol:: { sym, Symbol } ;
2422use rustc_span:: Span ;
2523use thin_vec:: ThinVec ;
@@ -48,42 +46,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
4846
4947 let mut features = Features :: default ( ) ;
5048
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-
8749 // Process all features declared in the code.
8850 for attr in krate_attrs {
8951 for mi in feature_list ( attr) {
@@ -108,38 +70,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
10870 }
10971 } ;
11072
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-
14373 // If the declared feature has been removed, issue an error.
14474 if let Some ( f) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
14575 sess. emit_err ( FeatureRemoved {
0 commit comments