diff options
| author | Pascal Hertleif <pascal@technocreatives.com> | 2019-08-24 17:50:21 +0200 |
|---|---|---|
| committer | Pascal Hertleif <pascal@technocreatives.com> | 2019-08-25 20:53:37 +0200 |
| commit | 94e8ff4f0b94c788ec9e9a28d3aa6f87062e2966 (patch) | |
| tree | 9ed95ede5b4474f8478d47de4d5b2df9099a7672 /src/libsyntax | |
| parent | c9d9616e825fecd4301beaf7bcd9115d5d7d393f (diff) | |
| download | rust-94e8ff4f0b94c788ec9e9a28d3aa6f87062e2966.tar.gz rust-94e8ff4f0b94c788ec9e9a28d3aa6f87062e2966.zip | |
Refactor feature gate checking code
Tries to clarify the filtering of active features and make the code more expressive.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate/check.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 344e5fd6e46..f3a9d135125 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -732,13 +732,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], } } - for &(name, .., f_edition, set) in ACTIVE_FEATURES { - if let Some(f_edition) = f_edition { - if f_edition <= crate_edition { - set(&mut features, DUMMY_SP); - edition_enabled_features.insert(name, crate_edition); - } - } + for feature in active_features_up_to(crate_edition) { + feature.set(&mut features, DUMMY_SP); + edition_enabled_features.insert(feature.name, crate_edition); } // 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(); - if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) { - if *edition <= crate_edition { + let edition = ALL_EDITIONS.iter().find(|e| name == e.feature_name()).copied(); + if let Some(edition) = edition { + if edition <= crate_edition { continue; } - for &(name, .., f_edition, set) in ACTIVE_FEATURES { - if let Some(f_edition) = f_edition { - if f_edition <= *edition { - // FIXME(Manishearth) there is currently no way to set - // lib features by edition - set(&mut features, DUMMY_SP); - edition_enabled_features.insert(name, *edition); - } - } + for feature in active_features_up_to(edition) { + // FIXME(Manishearth) there is currently no way to set + // lib features by edition + feature.set(&mut features, DUMMY_SP); + edition_enabled_features.insert(feature.name, edition); } } } @@ -867,6 +860,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], 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, sess: &ParseSess, features: &Features, |
