From 95208044e86af21569484c67a6b5bfd7eaa32b2f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 17 Jul 2018 19:56:41 +0200 Subject: [PATCH] Make `async_idents` an edition incompat lint --- src/librustc_lint/builtin.rs | 4 +- src/librustc_lint/lib.rs | 6 +- .../ui/auxiliary/edition-kw-macro-2015.rs | 1 + .../ui/auxiliary/edition-kw-macro-2018.rs | 1 + .../edition-keywords-2015-2015-expansion.rs | 1 + .../edition-keywords-2018-2015-expansion.rs | 1 + src/test/ui/rust-2018/async-ident.fixed | 61 ++++++++- src/test/ui/rust-2018/async-ident.rs | 61 ++++++++- src/test/ui/rust-2018/async-ident.stderr | 120 ++++++++++++++++-- 9 files changed, 238 insertions(+), 18 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 6950166a5cd94..4897b7406f8e3 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1788,7 +1788,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestFunctions { declare_lint! { pub ASYNC_IDENTS, - Allow, + Deny, "detects `async` being used as an identifier" } @@ -1798,7 +1798,7 @@ pub struct Async2018; impl LintPass for Async2018 { fn get_lints(&self) -> LintArray { - lint_array!() + lint_array!(ASYNC_IDENTS) } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 399725c0023f8..bb0f0e7832fd2 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -189,7 +189,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { add_lint_group!(sess, "rust_2018_idioms", BARE_TRAIT_OBJECTS, - ASYNC_IDENTS, UNREACHABLE_PUB, UNUSED_EXTERN_CRATES, ELLIPSIS_INCLUSIVE_RANGE_PATTERNS); @@ -224,6 +223,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #35896 ", edition: Some(Edition::Edition2018), }, + FutureIncompatibleInfo { + id: LintId::of(ASYNC_IDENTS), + reference: "issue #49716 ", + edition: Some(Edition::Edition2018), + }, FutureIncompatibleInfo { id: LintId::of(SAFE_EXTERN_STATICS), reference: "issue #36247 ", diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs index 69952e9f90af6..8f80e000e3caf 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -11,6 +11,7 @@ // edition:2015 #![feature(raw_identifiers)] +#![allow(async_idents)] #[macro_export] macro_rules! produces_async { diff --git a/src/test/ui/auxiliary/edition-kw-macro-2018.rs b/src/test/ui/auxiliary/edition-kw-macro-2018.rs index 415988586a066..d42014766ec68 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2018.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2018.rs @@ -11,6 +11,7 @@ // edition:2018 #![feature(raw_identifiers)] +#![allow(async_idents)] #[macro_export] macro_rules! produces_async { diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.rs b/src/test/ui/edition-keywords-2015-2015-expansion.rs index 349ab3e27ad32..3b78ce80be208 100644 --- a/src/test/ui/edition-keywords-2015-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2015-expansion.rs @@ -13,6 +13,7 @@ // compile-pass #![feature(raw_identifiers)] +#![allow(async_idents)] #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/ui/edition-keywords-2018-2015-expansion.rs b/src/test/ui/edition-keywords-2018-2015-expansion.rs index 6e2073e0e494a..be22d8b9b0105 100644 --- a/src/test/ui/edition-keywords-2018-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2018-2015-expansion.rs @@ -13,6 +13,7 @@ // compile-pass #![feature(raw_identifiers)] +#![allow(async_idents)] #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/ui/rust-2018/async-ident.fixed b/src/test/ui/rust-2018/async-ident.fixed index 8ede6c07bf8b9..dc44fec912e0a 100644 --- a/src/test/ui/rust-2018/async-ident.fixed +++ b/src/test/ui/rust-2018/async-ident.fixed @@ -9,18 +9,21 @@ // except according to those terms. #![feature(raw_identifiers)] -#![deny(rust_2018_idioms)] -#![allow(dead_code)] +#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] +// edition:2015 // run-rustfix fn r#async() {} //~ ERROR async +//~^ WARN hard error in the 2018 edition macro_rules! foo { ($foo:ident) => {}; ($r#async:expr, r#async) => {}; //~^ ERROR async //~| ERROR async + //~| WARN hard error in the 2018 edition + //~| WARN hard error in the 2018 edition } foo!(async); @@ -29,4 +32,56 @@ mod dont_lint_raw { fn r#async() {} } -fn main() {} +mod async_trait { + trait r#async {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition + struct MyStruct; + impl r#async for MyStruct {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +mod async_static { + static r#async: u32 = 0; + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +mod async_const { + const r#async: u32 = 0; + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +struct Foo; +impl Foo { fn r#async() {} } + //~^ ERROR async + //~| WARN hard error in the 2018 edition + +fn main() { + struct r#async {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition + let r#async: r#async = r#async {}; + //~^ ERROR async + //~| WARN hard error in the 2018 edition + //~| ERROR async + //~| WARN hard error in the 2018 edition + //~| ERROR async + //~| WARN hard error in the 2018 edition +} + +#[macro_export] +macro_rules! produces_async { + () => (pub fn r#async() {}) + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +#[macro_export] +macro_rules! consumes_async { + (r#async) => (1) + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} \ No newline at end of file diff --git a/src/test/ui/rust-2018/async-ident.rs b/src/test/ui/rust-2018/async-ident.rs index 6e529ec0229d1..6fffad0ce9b70 100644 --- a/src/test/ui/rust-2018/async-ident.rs +++ b/src/test/ui/rust-2018/async-ident.rs @@ -9,18 +9,21 @@ // except according to those terms. #![feature(raw_identifiers)] -#![deny(rust_2018_idioms)] -#![allow(dead_code)] +#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] +// edition:2015 // run-rustfix fn async() {} //~ ERROR async +//~^ WARN hard error in the 2018 edition macro_rules! foo { ($foo:ident) => {}; ($async:expr, async) => {}; //~^ ERROR async //~| ERROR async + //~| WARN hard error in the 2018 edition + //~| WARN hard error in the 2018 edition } foo!(async); @@ -29,4 +32,56 @@ mod dont_lint_raw { fn r#async() {} } -fn main() {} +mod async_trait { + trait async {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition + struct MyStruct; + impl async for MyStruct {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +mod async_static { + static async: u32 = 0; + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +mod async_const { + const async: u32 = 0; + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +struct Foo; +impl Foo { fn async() {} } + //~^ ERROR async + //~| WARN hard error in the 2018 edition + +fn main() { + struct async {} + //~^ ERROR async + //~| WARN hard error in the 2018 edition + let async: async = async {}; + //~^ ERROR async + //~| WARN hard error in the 2018 edition + //~| ERROR async + //~| WARN hard error in the 2018 edition + //~| ERROR async + //~| WARN hard error in the 2018 edition +} + +#[macro_export] +macro_rules! produces_async { + () => (pub fn async() {}) + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} + +#[macro_export] +macro_rules! consumes_async { + (async) => (1) + //~^ ERROR async + //~| WARN hard error in the 2018 edition +} \ No newline at end of file diff --git a/src/test/ui/rust-2018/async-ident.stderr b/src/test/ui/rust-2018/async-ident.stderr index 22a3e1aedcc3a..85596e8fe6b76 100644 --- a/src/test/ui/rust-2018/async-ident.stderr +++ b/src/test/ui/rust-2018/async-ident.stderr @@ -4,24 +4,126 @@ error: `async` is a keyword in the 2018 edition LL | fn async() {} //~ ERROR async | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` | -note: lint level defined here - --> $DIR/async-ident.rs:12:9 - | -LL | #![deny(rust_2018_idioms)] - | ^^^^^^^^^^^^^^^^ - = note: #[deny(async_idents)] implied by #[deny(rust_2018_idioms)] + = note: #[deny(async_idents)] on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:21:7 + --> $DIR/async-ident.rs:22:7 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:21:19 + --> $DIR/async-ident.rs:22:19 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:36:11 + | +LL | trait async {} + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:40:10 + | +LL | impl async for MyStruct {} + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:46:12 + | +LL | static async: u32 = 0; + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:52:11 + | +LL | const async: u32 = 0; + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:58:15 + | +LL | impl Foo { fn async() {} } + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:63:12 + | +LL | struct async {} + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:66:9 + | +LL | let async: async = async {}; + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:66:16 + | +LL | let async: async = async {}; + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:66:24 + | +LL | let async: async = async {}; + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:77:19 + | +LL | () => (pub fn async() {}) + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:84:6 + | +LL | (async) => (1) + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 -error: aborting due to 3 previous errors +error: aborting due to 14 previous errors