Generalize async_idents to all new keywords

This commit generalizes the existing `async_idents` lint to easily encompass
other identifiers that will be keywords in future editions. The new lint is
called `keyword_idents` and the old `async_idents` lint is registered as renamed
to this new lint.

As a proof of concept the `try` keyword was added to this list as it looks to be
listed as a keyword in the 2018 edition only. The `await` keyword was not added
as it's not listed as a keyword yet.

Closes #53077
This commit is contained in:
Alex Crichton 2018-08-24 13:48:20 -07:00
parent e6b35b0e11
commit 003cab25d7
14 changed files with 125 additions and 45 deletions

View file

@ -10,7 +10,7 @@
// edition:2015
#![allow(async_idents)]
#![allow(keyword_idents)]
#[macro_export]
macro_rules! produces_async {

View file

@ -10,7 +10,7 @@
// edition:2018
#![allow(async_idents)]
#![allow(keyword_idents)]
#[macro_export]
macro_rules! produces_async {

View file

@ -12,7 +12,7 @@
// aux-build:edition-kw-macro-2015.rs
// compile-pass
#![allow(async_idents)]
#![allow(keyword_idents)]
#[macro_use]
extern crate edition_kw_macro_2015;

View file

@ -12,7 +12,7 @@
// aux-build:edition-kw-macro-2015.rs
// compile-pass
#![allow(async_idents)]
#![allow(keyword_idents)]
#[macro_use]
extern crate edition_kw_macro_2015;

View file

@ -9,7 +9,7 @@ note: lint level defined here
|
LL | #![deny(rust_2018_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: #[deny(async_idents)] implied by #[deny(rust_2018_compatibility)]
= note: #[deny(keyword_idents)] implied by #[deny(rust_2018_compatibility)]
= 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>

View file

@ -9,7 +9,7 @@
// except according to those terms.
#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)]
#![deny(async_idents)]
#![deny(keyword_idents)]
// edition:2015
// run-rustfix

View file

@ -9,7 +9,7 @@
// except according to those terms.
#![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)]
#![deny(async_idents)]
#![deny(keyword_idents)]
// edition:2015
// run-rustfix

View file

@ -7,8 +7,8 @@ LL | fn async() {} //~ ERROR async
note: lint level defined here
--> $DIR/async-ident.rs:12:9
|
LL | #![deny(async_idents)]
| ^^^^^^^^^^^^
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
= 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>

View file

@ -0,0 +1,21 @@
// 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.
// run-rustfix
// compile-pass
#![warn(rust_2018_compatibility)]
fn main() {
r#try();
}
fn r#try() {
}

View file

@ -0,0 +1,21 @@
// 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.
// run-rustfix
// compile-pass
#![warn(rust_2018_compatibility)]
fn main() {
try();
}
fn try() {
}

View file

@ -0,0 +1,24 @@
warning: `try` is a keyword in the 2018 edition
--> $DIR/try-ident.rs:17:5
|
LL | try();
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
note: lint level defined here
--> $DIR/try-ident.rs:14:9
|
LL | #![warn(rust_2018_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: #[warn(keyword_idents)] implied by #[warn(rust_2018_compatibility)]
= 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>
warning: `try` is a keyword in the 2018 edition
--> $DIR/try-ident.rs:20:4
|
LL | fn try() {
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
= 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>