Skip to content

Commit 94e8ff4

Browse files
author
Pascal Hertleif
committed
Refactor feature gate checking code
Tries to clarify the filtering of active features and make the code more expressive.
1 parent c9d9616 commit 94e8ff4

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/libsyntax/feature_gate/check.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
732732
}
733733
}
734734

735-
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
736-
if let Some(f_edition) = f_edition {
737-
if f_edition <= crate_edition {
738-
set(&mut features, DUMMY_SP);
739-
edition_enabled_features.insert(name, crate_edition);
740-
}
741-
}
735+
for feature in active_features_up_to(crate_edition) {
736+
feature.set(&mut features, DUMMY_SP);
737+
edition_enabled_features.insert(feature.name, crate_edition);
742738
}
743739

744740
// Process the edition umbrella feature-gates first, to ensure
@@ -760,20 +756,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
760756

761757
let name = mi.name_or_empty();
762758

763-
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
764-
if *edition <= crate_edition {
759+
let edition = ALL_EDITIONS.iter().find(|e| name == e.feature_name()).copied();
760+
if let Some(edition) = edition {
761+
if edition <= crate_edition {
765762
continue;
766763
}
767764

768-
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
769-
if let Some(f_edition) = f_edition {
770-
if f_edition <= *edition {
771-
// FIXME(Manishearth) there is currently no way to set
772-
// lib features by edition
773-
set(&mut features, DUMMY_SP);
774-
edition_enabled_features.insert(name, *edition);
775-
}
776-
}
765+
for feature in active_features_up_to(edition) {
766+
// FIXME(Manishearth) there is currently no way to set
767+
// lib features by edition
768+
feature.set(&mut features, DUMMY_SP);
769+
edition_enabled_features.insert(feature.name, edition);
777770
}
778771
}
779772
}
@@ -867,6 +860,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
867860
features
868861
}
869862

863+
fn active_features_up_to(edition: Edition) -> impl Iterator<Item=&'static Feature> {
864+
ACTIVE_FEATURES.iter()
865+
.filter(move |feature| {
866+
if let Some(feature_edition) = feature.edition {
867+
feature_edition <= edition
868+
} else {
869+
false
870+
}
871+
})
872+
}
873+
870874
pub fn check_crate(krate: &ast::Crate,
871875
sess: &ParseSess,
872876
features: &Features,

0 commit comments

Comments
 (0)