Refactor feature gate checking code
Tries to clarify the filtering of active features and make the code more expressive.
This commit is contained in:
@@ -732,13 +732,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
|
for feature in active_features_up_to(crate_edition) {
|
||||||
if let Some(f_edition) = f_edition {
|
feature.set(&mut features, DUMMY_SP);
|
||||||
if f_edition <= crate_edition {
|
edition_enabled_features.insert(feature.name, crate_edition);
|
||||||
set(&mut features, DUMMY_SP);
|
|
||||||
edition_enabled_features.insert(name, crate_edition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the edition umbrella feature-gates first, to ensure
|
// Process the edition umbrella feature-gates first, to ensure
|
||||||
@@ -760,20 +756,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
|||||||
|
|
||||||
let name = mi.name_or_empty();
|
let name = mi.name_or_empty();
|
||||||
|
|
||||||
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
|
let edition = ALL_EDITIONS.iter().find(|e| name == e.feature_name()).copied();
|
||||||
if *edition <= crate_edition {
|
if let Some(edition) = edition {
|
||||||
|
if edition <= crate_edition {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
|
for feature in active_features_up_to(edition) {
|
||||||
if let Some(f_edition) = f_edition {
|
// FIXME(Manishearth) there is currently no way to set
|
||||||
if f_edition <= *edition {
|
// lib features by edition
|
||||||
// FIXME(Manishearth) there is currently no way to set
|
feature.set(&mut features, DUMMY_SP);
|
||||||
// lib features by edition
|
edition_enabled_features.insert(feature.name, edition);
|
||||||
set(&mut features, DUMMY_SP);
|
|
||||||
edition_enabled_features.insert(name, *edition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -867,6 +860,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
|||||||
features
|
features
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn active_features_up_to(edition: Edition) -> impl Iterator<Item=&'static Feature> {
|
||||||
|
ACTIVE_FEATURES.iter()
|
||||||
|
.filter(move |feature| {
|
||||||
|
if let Some(feature_edition) = feature.edition {
|
||||||
|
feature_edition <= edition
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_crate(krate: &ast::Crate,
|
pub fn check_crate(krate: &ast::Crate,
|
||||||
sess: &ParseSess,
|
sess: &ParseSess,
|
||||||
features: &Features,
|
features: &Features,
|
||||||
|
|||||||
Reference in New Issue
Block a user