Skip to content

Commit 2c44026

Browse files
committed
syntax: also warn about edition "umbrella" features being implied by --edition.
1 parent 0f00979 commit 2c44026

8 files changed

+49
-20
lines changed

src/libsyntax/feature_gate.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,14 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19231923
let mut features = Features::new();
19241924
let mut edition_enabled_features = FxHashMap();
19251925

1926+
for &edition in ALL_EDITIONS {
1927+
if edition <= crate_edition {
1928+
// The `crate_edition` implies its respective umbrella feature-gate
1929+
// (i.e. `#![feature(rust_20XX_preview)]` isn't needed on edition 20XX).
1930+
edition_enabled_features.insert(Symbol::intern(edition.feature_name()), edition);
1931+
}
1932+
}
1933+
19261934
for &(name, .., f_edition, set) in ACTIVE_FEATURES {
19271935
if let Some(f_edition) = f_edition {
19281936
if f_edition <= crate_edition {
@@ -1993,25 +2001,26 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19932001
continue
19942002
};
19952003

2004+
if let Some(edition) = edition_enabled_features.get(&name) {
2005+
struct_span_warn!(
2006+
span_handler,
2007+
mi.span,
2008+
E0705,
2009+
"the feature `{}` is included in the Rust {} edition",
2010+
name,
2011+
edition,
2012+
).emit();
2013+
continue;
2014+
}
2015+
19962016
if ALL_EDITIONS.iter().any(|e| name == e.feature_name()) {
19972017
// Handled in the separate loop above.
19982018
continue;
19992019
}
20002020

20012021
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
2002-
if let Some(edition) = edition_enabled_features.get(&name) {
2003-
struct_span_warn!(
2004-
span_handler,
2005-
mi.span,
2006-
E0705,
2007-
"the feature `{}` is included in the Rust {} edition",
2008-
name,
2009-
edition,
2010-
).emit();
2011-
} else {
2012-
set(&mut features, mi.span);
2013-
features.declared_lang_features.push((name, mi.span, None));
2014-
}
2022+
set(&mut features, mi.span);
2023+
features.declared_lang_features.push((name, mi.span, None));
20152024
continue
20162025
}
20172026

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/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/rust-2018/extern-crate-idiomatic-in-2018.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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)