Skip to content

Commit

Permalink
Make async_idents an edition incompat lint
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jul 17, 2018
1 parent 15a8a66 commit 9520804
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Expand Up @@ -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"
}

Expand All @@ -1798,7 +1798,7 @@ pub struct Async2018;

impl LintPass for Async2018 {
fn get_lints(&self) -> LintArray {
lint_array!()
lint_array!(ASYNC_IDENTS)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustc_lint/lib.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -224,6 +223,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #35896 <https://github.com/rust-lang/rust/issues/35896>",
edition: Some(Edition::Edition2018),
},
FutureIncompatibleInfo {
id: LintId::of(ASYNC_IDENTS),
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
edition: Some(Edition::Edition2018),
},
FutureIncompatibleInfo {
id: LintId::of(SAFE_EXTERN_STATICS),
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/36247>",
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/auxiliary/edition-kw-macro-2015.rs
Expand Up @@ -11,6 +11,7 @@
// edition:2015

#![feature(raw_identifiers)]
#![allow(async_idents)]

#[macro_export]
macro_rules! produces_async {
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/auxiliary/edition-kw-macro-2018.rs
Expand Up @@ -11,6 +11,7 @@
// edition:2018

#![feature(raw_identifiers)]
#![allow(async_idents)]

#[macro_export]
macro_rules! produces_async {
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/edition-keywords-2015-2015-expansion.rs
Expand Up @@ -13,6 +13,7 @@
// compile-pass

#![feature(raw_identifiers)]
#![allow(async_idents)]

#[macro_use]
extern crate edition_kw_macro_2015;
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/edition-keywords-2018-2015-expansion.rs
Expand Up @@ -13,6 +13,7 @@
// compile-pass

#![feature(raw_identifiers)]
#![allow(async_idents)]

#[macro_use]
extern crate edition_kw_macro_2015;
Expand Down
61 changes: 58 additions & 3 deletions src/test/ui/rust-2018/async-ident.fixed
Expand Up @@ -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);
Expand All @@ -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
}
61 changes: 58 additions & 3 deletions src/test/ui/rust-2018/async-ident.rs
Expand Up @@ -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);
Expand All @@ -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
}
120 changes: 111 additions & 9 deletions src/test/ui/rust-2018/async-ident.stderr
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/49716>

error: aborting due to 3 previous errors
error: aborting due to 14 previous errors

0 comments on commit 9520804

Please sign in to comment.