diff options
| author | Corey Farwell <coreyf@rwell.org> | 2018-08-17 08:23:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-17 08:23:44 -0700 |
| commit | 5c7b837c4e0b7405726440533393c68521acfefe (patch) | |
| tree | b49c95d30d5aa90eaf907830f40c7ab36a771920 /src/libsyntax | |
| parent | 5ad7b914c0fe618c1499629e66ed0cf8d305449c (diff) | |
| parent | 32e17b5921ea3fbe90cb4b0e3760b03e3f22a143 (diff) | |
| download | rust-5c7b837c4e0b7405726440533393c68521acfefe.tar.gz rust-5c7b837c4e0b7405726440533393c68521acfefe.zip | |
Rollup merge of #53413 - eddyb:featured-in-the-latest-edition, r=varkor
Warn that `#![feature(rust_2018_preview)]` is implied when the edition is set to Rust 2018. cc @varkor @petrochenkov @joshtriplett
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 395e5c98652..7a8a7b07318 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1930,7 +1930,15 @@ 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 &edition in ALL_EDITIONS { + if edition <= crate_edition { + // The `crate_edition` implies its respective umbrella feature-gate + // (i.e. `#![feature(rust_20XX_preview)]` isn't needed on edition 20XX). + edition_enabled_features.insert(Symbol::intern(edition.feature_name()), edition); + } + } + + 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); @@ -1939,6 +1947,8 @@ 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 @@ -1946,19 +1956,13 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], let list = match attr.meta_item_list() { Some(list) => list, - None => { - span_err!(span_handler, attr.span, E0555, - "malformed feature attribute, expected #![feature(...)]"); - continue - } + None => continue, }; for mi in list { let name = if let Some(word) = mi.word() { word.name() } else { - span_err!(span_handler, mi.span, E0556, - "malformed feature, expected just one word"); continue }; @@ -1974,10 +1978,10 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) { if *edition <= crate_edition { - continue + continue; } - 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 <= *edition { // FIXME(Manishearth) there is currently no way to set @@ -1987,24 +1991,53 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], } } } + } + } + } + + for attr in krate_attrs { + if !attr.check_name("feature") { + continue + } + + let list = match attr.meta_item_list() { + Some(list) => list, + None => { + span_err!(span_handler, attr.span, E0555, + "malformed feature attribute, expected #![feature(...)]"); + continue + } + }; + for mi in list { + let name = if let Some(word) = mi.word() { + word.name() + } else { + span_err!(span_handler, mi.span, E0556, + "malformed feature, expected just one word"); continue + }; + + if let Some(edition) = edition_enabled_features.get(&name) { + struct_span_warn!( + span_handler, + mi.span, + E0705, + "the feature `{}` is included in the Rust {} edition", + name, + edition, + ).emit(); + 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) { - if let Some(edition) = edition_enabled_features.get(&name) { - struct_span_warn!( - span_handler, - mi.span, - E0705, - "the feature `{}` is included in the Rust {} edition", - name, - edition, - ).emit(); - } else { - set(&mut features, mi.span); - features.declared_lang_features.push((name, mi.span, None)); - } + set(&mut features, mi.span); + features.declared_lang_features.push((name, mi.span, None)); continue } |
