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

Lines changed: 56 additions & 23 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)