Skip to content

Commit

Permalink
Rollup merge of rust-lang#53413 - eddyb:featured-in-the-latest-editio…
Browse files Browse the repository at this point in the history
…n, r=varkor

Warn that `#![feature(rust_2018_preview)]` is implied when the edition is set to Rust 2018.

cc @varkor @petrochenkov @joshtriplett
  • Loading branch information
frewsxcv authored Aug 17, 2018
2 parents 5ad7b91 + 32e17b5 commit 5c7b837
Show file tree
Hide file tree
Showing 29 changed files with 106 additions and 53 deletions.
79 changes: 56 additions & 23 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1939,26 +1947,22 @@ 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 => {
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
};

Expand All @@ -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
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/macro-at-most-once-rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//
// This test focuses on non-error cases and making sure the correct number of repetitions happen.

// compile-flags: --edition=2018
// edition:2018

#![feature(macro_at_most_once_rep)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/async-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive

#![feature(rust_2018_preview, async_await, futures_api)]
#![feature(async_await, futures_api)]

// @has async_fn/struct.S.html
// @has - '//code' 'pub async fn f()'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// aux-build:suggestions-not-always-applicable.rs
// compile-flags: --edition 2015
// edition:2015
// run-rustfix
// rustfix-only-machine-applicable
// compile-pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// aux-build:suggestions-not-always-applicable.rs
// compile-flags: --edition 2015
// edition:2015
// run-rustfix
// rustfix-only-machine-applicable
// compile-pass
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/unnecessary-extern-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: --edition 2018
// edition:2018

#![deny(unused_extern_crates)]
#![feature(alloc, test, libc)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/E0705.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/E0705.stderr
Original file line number Diff line number Diff line change
@@ -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)]
| ^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// revisions: zflag edition
// [zflag]compile-flags: -Z borrowck=migrate
// [edition]compile-flags: --edition 2018
// [edition]edition:2018

#![feature(nll)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-migrate-to-nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// revisions: zflag edition
//[zflag]compile-flags: -Z borrowck=migrate
//[edition]compile-flags: --edition 2018
//[edition]edition:2018
//[zflag] run-pass
//[edition] run-pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// revisions: ast zflags edition
//[zflags]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
//[edition]compile-flags: --edition 2018
//[edition]edition:2018

// run-pass

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/editions/edition-extern-crate-allowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// aux-build:edition-extern-crate-allowed.rs
// compile-flags: --edition 2015
// edition:2015
// compile-pass

#![warn(rust_2018_idioms)]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/editions/edition-feature-ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags:--edition 2018
// compile-pass

#![feature(rust_2018_preview)]
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/editions/edition-feature-redundant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// edition:2018
// compile-pass

#![feature(rust_2018_preview)]
//~^ WARN the feature `rust_2018_preview` is included in the Rust 2018 edition

fn main() {}
6 changes: 6 additions & 0 deletions src/test/ui/editions/edition-feature-redundant.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning[E0705]: the feature `rust_2018_preview` is included in the Rust 2018 edition
--> $DIR/edition-feature-redundant.rs:14:12
|
LL | #![feature(rust_2018_preview)]
| ^^^^^^^^^^^^^^^^^

2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/elided-lifetimes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// run-rustfix
// compile-flags: --edition 2018
// edition:2018

#![allow(unused)]
#![deny(elided_lifetimes_in_paths)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/elided-lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// run-rustfix
// compile-flags: --edition 2018
// edition:2018

#![allow(unused)]
#![deny(elided_lifetimes_in_paths)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// with the feature flag.

// gate-test-macro_at_most_once_rep
// compile-flags: --edition=2015
// edition:2015

#![feature(macro_at_most_once_rep)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Test behavior of `?` macro _kleene op_ under the 2015 edition. Namely, it doesn't exist.

// compile-flags: --edition=2015
// edition:2015

macro_rules! bar {
($(a)?) => {} //~ERROR expected `*` or `+`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Test behavior of `?` macro _separator_ under the 2015 edition. Namely, `?` can be used as a
// separator, but you get a migration warning for the edition.

// compile-flags: --edition=2015
// edition:2015
// compile-pass

#![warn(rust_2018_compatibility)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Feature gate test for macro_at_most_once_rep under 2018 edition.

// gate-test-macro_at_most_once_rep
// compile-flags: --edition=2018
// edition:2018

macro_rules! foo {
($(a)?) => {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-at-most-once-rep-2018.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Tests that `?` is a Kleene op and not a macro separator in the 2018 edition.

// compile-flags: --edition=2018
// edition:2018

#![feature(macro_at_most_once_rep)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/removing-extern-crate.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: --edition 2018
// edition:2018
// aux-build:removing-extern-crate.rs
// run-rustfix
// compile-pass
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/removing-extern-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: --edition 2018
// edition:2018
// aux-build:removing-extern-crate.rs
// run-rustfix
// compile-pass
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rust-2018/async-ident-allowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: --edition 2015
// edition:2015

#![deny(rust_2018_compatibility)]

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

// aux-build:edition-lint-paths.rs
// run-rustfix
// compile-flags:--edition 2018
// edition:2018

// The "normal case". Ideally we would remove the `extern crate` here,
// but we don't.

#![feature(rust_2018_preview)]
#![deny(rust_2018_idioms)]
#![allow(dead_code)]

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

// aux-build:edition-lint-paths.rs
// run-rustfix
// compile-flags:--edition 2018
// edition:2018

// The "normal case". Ideally we would remove the `extern crate` here,
// but we don't.

#![feature(rust_2018_preview)]
#![deny(rust_2018_idioms)]
#![allow(dead_code)]

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error: unused extern crate
--> $DIR/extern-crate-idiomatic-in-2018.rs:22:1
--> $DIR/extern-crate-idiomatic-in-2018.rs:21:1
|
LL | extern crate edition_lint_paths;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
|
note: lint level defined here
--> $DIR/extern-crate-idiomatic-in-2018.rs:19:9
--> $DIR/extern-crate-idiomatic-in-2018.rs:18:9
|
LL | #![deny(rust_2018_idioms)]
| ^^^^^^^^^^^^^^^^
= note: #[deny(unused_extern_crates)] implied by #[deny(rust_2018_idioms)]

error: `extern crate` is not idiomatic in the new edition
--> $DIR/extern-crate-idiomatic-in-2018.rs:25:1
--> $DIR/extern-crate-idiomatic-in-2018.rs:24:1
|
LL | extern crate edition_lint_paths as bar;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
Expand Down
Loading

0 comments on commit 5c7b837

Please sign in to comment.