syntax: also warn about edition "umbrella" features being implied by --edition.
This commit is contained in:
parent
0f00979517
commit
2c4402638e
@ -1923,6 +1923,14 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
let mut features = Features::new();
|
||||
let mut edition_enabled_features = FxHashMap();
|
||||
|
||||
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 {
|
||||
@ -1993,12 +2001,6 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
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,
|
||||
@ -2008,10 +2010,17 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
name,
|
||||
edition,
|
||||
).emit();
|
||||
} else {
|
||||
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) {
|
||||
set(&mut features, mi.span);
|
||||
features.declared_lang_features.push((name, mi.span, None));
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -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()'
|
||||
|
@ -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)]
|
||||
|
17
src/test/ui/editions/edition-feature-redundant.rs
Normal file
17
src/test/ui/editions/edition-feature-redundant.rs
Normal file
@ -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
src/test/ui/editions/edition-feature-redundant.stderr
Normal file
6
src/test/ui/editions/edition-feature-redundant.stderr
Normal file
@ -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)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -15,7 +15,6 @@
|
||||
// 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)]
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
// 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)]
|
||||
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user