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 } ;
@@ -12,13 +12,11 @@ use rustc_ast::NodeId;
1212use rustc_ast:: { self as ast, AttrStyle , Attribute , HasAttrs , HasTokens , MetaItem } ;
1313use rustc_attr as attr;
1414use rustc_data_structures:: flat_map_in_place:: FlatMapInPlace ;
15- use rustc_data_structures:: fx:: FxHashSet ;
1615use rustc_feature:: Features ;
1716use rustc_feature:: { ACCEPTED_FEATURES , REMOVED_FEATURES , UNSTABLE_FEATURES } ;
1817use rustc_parse:: validate_attr;
1918use rustc_session:: parse:: feature_err;
2019use rustc_session:: Session ;
21- use rustc_span:: edition:: ALL_EDITIONS ;
2220use rustc_span:: symbol:: { sym, Symbol } ;
2321use rustc_span:: Span ;
2422use thin_vec:: ThinVec ;
@@ -47,42 +45,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
4745
4846 let mut features = Features :: default ( ) ;
4947
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-
8648 // Process all features declared in the code.
8749 for attr in krate_attrs {
8850 for mi in feature_list ( attr) {
@@ -107,38 +69,6 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
10769 }
10870 } ;
10971
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-
14272 // If the declared feature has been removed, issue an error.
14373 if let Some ( f) = REMOVED_FEATURES . iter ( ) . find ( |f| name == f. feature . name ) {
14474 sess. emit_err ( FeatureRemoved {
0 commit comments