diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 56e69b9df9e0..74db42ead7d4 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1923,7 +1923,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], let mut features = Features::new(); let mut edition_enabled_features = FxHashMap(); - for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() { + 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); @@ -1932,6 +1932,44 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], } } + // Process the edition umbrella feature-gates first, to ensure + // `edition_enabled_features` is completed before it's queried. + for attr in krate_attrs { + if !attr.check_name("feature") { + continue + } + + let list = match attr.meta_item_list() { + Some(list) => list, + None => continue, + }; + + for mi in list { + let name = if let Some(word) = mi.word() { + word.name() + } else { + continue + }; + + if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) { + 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(Symbol::intern(name), *edition); + } + } + } + } + } + } + for attr in krate_attrs { if !attr.check_name("feature") { continue @@ -1955,23 +1993,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], continue }; - if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) { - if *edition <= crate_edition { - continue - } - - for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() { - 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(Symbol::intern(name), *edition); - } - } - } - - continue + if ALL_EDITIONS.iter().any(|e| name == e.feature_name()) { + // Handled in the separate loop above. + continue; } if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) { diff --git a/src/test/ui/E0705.rs b/src/test/ui/E0705.rs index a0ce95e3e02c..b5fd3cf35f28 100644 --- a/src/test/ui/E0705.rs +++ b/src/test/ui/E0705.rs @@ -10,9 +10,9 @@ // compile-pass -#![feature(rust_2018_preview)] #![feature(raw_identifiers)] //~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition +#![feature(rust_2018_preview)] fn main() { let foo = 0; diff --git a/src/test/ui/E0705.stderr b/src/test/ui/E0705.stderr index ebb8dd4975d6..2aa3077e48c2 100644 --- a/src/test/ui/E0705.stderr +++ b/src/test/ui/E0705.stderr @@ -1,5 +1,5 @@ warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition - --> $DIR/E0705.rs:14:12 + --> $DIR/E0705.rs:13:12 | LL | #![feature(raw_identifiers)] | ^^^^^^^^^^^^^^^