Skip to content

Commit 5c7b837

Browse files
authored
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
2 parents 5ad7b91 + 32e17b5 commit 5c7b837

29 files changed

+106
-53
lines changed

src/libsyntax/feature_gate.rs

+56-23
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,15 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19301930
let mut features = Features::new();
19311931
let mut edition_enabled_features = FxHashMap();
19321932

1933-
for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
1933+
for &edition in ALL_EDITIONS {
1934+
if edition <= crate_edition {
1935+
// The `crate_edition` implies its respective umbrella feature-gate
1936+
// (i.e. `#![feature(rust_20XX_preview)]` isn't needed on edition 20XX).
1937+
edition_enabled_features.insert(Symbol::intern(edition.feature_name()), edition);
1938+
}
1939+
}
1940+
1941+
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
19341942
if let Some(f_edition) = f_edition {
19351943
if f_edition <= crate_edition {
19361944
set(&mut features, DUMMY_SP);
@@ -1939,26 +1947,22 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19391947
}
19401948
}
19411949

1950+
// Process the edition umbrella feature-gates first, to ensure
1951+
// `edition_enabled_features` is completed before it's queried.
19421952
for attr in krate_attrs {
19431953
if !attr.check_name("feature") {
19441954
continue
19451955
}
19461956

19471957
let list = match attr.meta_item_list() {
19481958
Some(list) => list,
1949-
None => {
1950-
span_err!(span_handler, attr.span, E0555,
1951-
"malformed feature attribute, expected #![feature(...)]");
1952-
continue
1953-
}
1959+
None => continue,
19541960
};
19551961

19561962
for mi in list {
19571963
let name = if let Some(word) = mi.word() {
19581964
word.name()
19591965
} else {
1960-
span_err!(span_handler, mi.span, E0556,
1961-
"malformed feature, expected just one word");
19621966
continue
19631967
};
19641968

@@ -1974,10 +1978,10 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19741978

19751979
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
19761980
if *edition <= crate_edition {
1977-
continue
1981+
continue;
19781982
}
19791983

1980-
for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
1984+
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
19811985
if let Some(f_edition) = f_edition {
19821986
if f_edition <= *edition {
19831987
// FIXME(Manishearth) there is currently no way to set
@@ -1987,24 +1991,53 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19871991
}
19881992
}
19891993
}
1994+
}
1995+
}
1996+
}
1997+
1998+
for attr in krate_attrs {
1999+
if !attr.check_name("feature") {
2000+
continue
2001+
}
2002+
2003+
let list = match attr.meta_item_list() {
2004+
Some(list) => list,
2005+
None => {
2006+
span_err!(span_handler, attr.span, E0555,
2007+
"malformed feature attribute, expected #![feature(...)]");
2008+
continue
2009+
}
2010+
};
19902011

2012+
for mi in list {
2013+
let name = if let Some(word) = mi.word() {
2014+
word.name()
2015+
} else {
2016+
span_err!(span_handler, mi.span, E0556,
2017+
"malformed feature, expected just one word");
19912018
continue
2019+
};
2020+
2021+
if let Some(edition) = edition_enabled_features.get(&name) {
2022+
struct_span_warn!(
2023+
span_handler,
2024+
mi.span,
2025+
E0705,
2026+
"the feature `{}` is included in the Rust {} edition",
2027+
name,
2028+
edition,
2029+
).emit();
2030+
continue;
2031+
}
2032+
2033+
if ALL_EDITIONS.iter().any(|e| name == e.feature_name()) {
2034+
// Handled in the separate loop above.
2035+
continue;
19922036
}
19932037

19942038
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
1995-
if let Some(edition) = edition_enabled_features.get(&name) {
1996-
struct_span_warn!(
1997-
span_handler,
1998-
mi.span,
1999-
E0705,
2000-
"the feature `{}` is included in the Rust {} edition",
2001-
name,
2002-
edition,
2003-
).emit();
2004-
} else {
2005-
set(&mut features, mi.span);
2006-
features.declared_lang_features.push((name, mi.span, None));
2007-
}
2039+
set(&mut features, mi.span);
2040+
features.declared_lang_features.push((name, mi.span, None));
20082041
continue
20092042
}
20102043

src/test/run-pass/macro-at-most-once-rep.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
// This test focuses on non-error cases and making sure the correct number of repetitions happen.
2020

21-
// compile-flags: --edition=2018
21+
// edition:2018
2222

2323
#![feature(macro_at_most_once_rep)]
2424

src/test/rustdoc/async-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

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

16-
#![feature(rust_2018_preview, async_await, futures_api)]
16+
#![feature(async_await, futures_api)]
1717

1818
// @has async_fn/struct.S.html
1919
// @has - '//code' 'pub async fn f()'

src/test/ui-fulldeps/rust-2018/suggestions-not-always-applicable.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:suggestions-not-always-applicable.rs
12-
// compile-flags: --edition 2015
12+
// edition:2015
1313
// run-rustfix
1414
// rustfix-only-machine-applicable
1515
// compile-pass

src/test/ui-fulldeps/rust-2018/suggestions-not-always-applicable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:suggestions-not-always-applicable.rs
12-
// compile-flags: --edition 2015
12+
// edition:2015
1313
// run-rustfix
1414
// rustfix-only-machine-applicable
1515
// compile-pass

src/test/ui-fulldeps/unnecessary-extern-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: --edition 2018
11+
// edition:2018
1212

1313
#![deny(unused_extern_crates)]
1414
#![feature(alloc, test, libc)]

src/test/ui/E0705.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
// compile-pass
1212

13-
#![feature(rust_2018_preview)]
1413
#![feature(raw_identifiers)]
1514
//~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition
15+
#![feature(rust_2018_preview)]
1616

1717
fn main() {
1818
let foo = 0;

src/test/ui/E0705.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition
2-
--> $DIR/E0705.rs:14:12
2+
--> $DIR/E0705.rs:13:12
33
|
44
LL | #![feature(raw_identifiers)]
55
| ^^^^^^^^^^^^^^^

src/test/ui/borrowck/borrowck-feature-nll-overrides-migrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// revisions: zflag edition
2222
// [zflag]compile-flags: -Z borrowck=migrate
23-
// [edition]compile-flags: --edition 2018
23+
// [edition]edition:2018
2424

2525
#![feature(nll)]
2626

src/test/ui/borrowck/borrowck-migrate-to-nll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// revisions: zflag edition
2525
//[zflag]compile-flags: -Z borrowck=migrate
26-
//[edition]compile-flags: --edition 2018
26+
//[edition]edition:2018
2727
//[zflag] run-pass
2828
//[edition] run-pass
2929

src/test/ui/borrowck/issue-52967-edition-2018-needs-two-phase-borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// revisions: ast zflags edition
1616
//[zflags]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
17-
//[edition]compile-flags: --edition 2018
17+
//[edition]edition:2018
1818

1919
// run-pass
2020

src/test/ui/editions/edition-extern-crate-allowed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:edition-extern-crate-allowed.rs
12-
// compile-flags: --edition 2015
12+
// edition:2015
1313
// compile-pass
1414

1515
#![warn(rust_2018_idioms)]

src/test/ui/editions/edition-feature-ok.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags:--edition 2018
1211
// compile-pass
1312

1413
#![feature(rust_2018_preview)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
// compile-pass
13+
14+
#![feature(rust_2018_preview)]
15+
//~^ WARN the feature `rust_2018_preview` is included in the Rust 2018 edition
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning[E0705]: the feature `rust_2018_preview` is included in the Rust 2018 edition
2+
--> $DIR/edition-feature-redundant.rs:14:12
3+
|
4+
LL | #![feature(rust_2018_preview)]
5+
| ^^^^^^^^^^^^^^^^^
6+

src/test/ui/in-band-lifetimes/elided-lifetimes.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// run-rustfix
12-
// compile-flags: --edition 2018
12+
// edition:2018
1313

1414
#![allow(unused)]
1515
#![deny(elided_lifetimes_in_paths)]

src/test/ui/in-band-lifetimes/elided-lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// run-rustfix
12-
// compile-flags: --edition 2018
12+
// edition:2018
1313

1414
#![allow(unused)]
1515
#![deny(elided_lifetimes_in_paths)]

src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep-feature-flag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// with the feature flag.
1313

1414
// gate-test-macro_at_most_once_rep
15-
// compile-flags: --edition=2015
15+
// edition:2015
1616

1717
#![feature(macro_at_most_once_rep)]
1818

src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
// compile-flags: --edition=2015
13+
// edition:2015
1414

1515
macro_rules! bar {
1616
($(a)?) => {} //~ERROR expected `*` or `+`

src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Test behavior of `?` macro _separator_ under the 2015 edition. Namely, `?` can be used as a
1212
// separator, but you get a migration warning for the edition.
1313

14-
// compile-flags: --edition=2015
14+
// edition:2015
1515
// compile-pass
1616

1717
#![warn(rust_2018_compatibility)]

src/test/ui/macros/macro-at-most-once-rep-2018-feature-gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Feature gate test for macro_at_most_once_rep under 2018 edition.
1212

1313
// gate-test-macro_at_most_once_rep
14-
// compile-flags: --edition=2018
14+
// edition:2018
1515

1616
macro_rules! foo {
1717
($(a)?) => {}

src/test/ui/macros/macro-at-most-once-rep-2018.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
// compile-flags: --edition=2018
13+
// edition:2018
1414

1515
#![feature(macro_at_most_once_rep)]
1616

src/test/ui/removing-extern-crate.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: --edition 2018
11+
// edition:2018
1212
// aux-build:removing-extern-crate.rs
1313
// run-rustfix
1414
// compile-pass

src/test/ui/removing-extern-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: --edition 2018
11+
// edition:2018
1212
// aux-build:removing-extern-crate.rs
1313
// run-rustfix
1414
// compile-pass

src/test/ui/rust-2018/async-ident-allowed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: --edition 2015
11+
// edition:2015
1212

1313
#![deny(rust_2018_compatibility)]
1414

src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
// aux-build:edition-lint-paths.rs
1212
// run-rustfix
13-
// compile-flags:--edition 2018
13+
// edition:2018
1414

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

18-
#![feature(rust_2018_preview)]
1918
#![deny(rust_2018_idioms)]
2019
#![allow(dead_code)]
2120

src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
// aux-build:edition-lint-paths.rs
1212
// run-rustfix
13-
// compile-flags:--edition 2018
13+
// edition:2018
1414

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

18-
#![feature(rust_2018_preview)]
1918
#![deny(rust_2018_idioms)]
2019
#![allow(dead_code)]
2120

src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error: unused extern crate
2-
--> $DIR/extern-crate-idiomatic-in-2018.rs:22:1
2+
--> $DIR/extern-crate-idiomatic-in-2018.rs:21:1
33
|
44
LL | extern crate edition_lint_paths;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
66
|
77
note: lint level defined here
8-
--> $DIR/extern-crate-idiomatic-in-2018.rs:19:9
8+
--> $DIR/extern-crate-idiomatic-in-2018.rs:18:9
99
|
1010
LL | #![deny(rust_2018_idioms)]
1111
| ^^^^^^^^^^^^^^^^
1212
= note: #[deny(unused_extern_crates)] implied by #[deny(rust_2018_idioms)]
1313

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

0 commit comments

Comments
 (0)