forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some tests illustrating where the revised lint does and does not apply.
- Loading branch information
Showing
5 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Under the 2015 edition with the keyword_idents lint, `dyn` is not | ||
// entirely acceptable as an identifier. We currently do not attempt | ||
// to detect or fix uses of `dyn` under a macro. Since we are testing | ||
// this file via `rustfix`, we want the rustfix output to be | ||
// compilable; so the macros here carefully use `dyn` "correctly." | ||
|
||
// run-rustfix | ||
|
||
#![allow(non_camel_case_types)] | ||
#![deny(keyword_idents)] | ||
|
||
mod outer_mod { | ||
pub mod r#dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
pub struct r#dyn; | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
} | ||
} | ||
use outer_mod::r#dyn::r#dyn; | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
fn main() { | ||
match r#dyn { r#dyn => {} } | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
macro_defn::r#dyn(); | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
macro_defn::boxed(); | ||
} | ||
|
||
mod macro_defn { | ||
use super::Trait; | ||
|
||
macro_rules! r#dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
// Note that we do not lint nor fix occurrences under macros | ||
($dyn:ident) => { Box<dyn Trait> } | ||
} | ||
|
||
pub fn r#dyn() -> ::outer_mod::r#dyn::r#dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
::outer_mod::r#dyn::r#dyn | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
} | ||
|
||
|
||
|
||
pub fn boxed() -> r#dyn!( | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
// Note that we do not lint nor fix occurrences under macros | ||
dyn | ||
) | ||
{ | ||
Box::new(10) | ||
} | ||
} | ||
|
||
pub trait Trait { } | ||
|
||
impl Trait for u32 { } |
81 changes: 81 additions & 0 deletions
81
src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Under the 2015 edition with the keyword_idents lint, `dyn` is not | ||
// entirely acceptable as an identifier. We currently do not attempt | ||
// to detect or fix uses of `dyn` under a macro. Since we are testing | ||
// this file via `rustfix`, we want the rustfix output to be | ||
// compilable; so the macros here carefully use `dyn` "correctly." | ||
|
||
// run-rustfix | ||
|
||
#![allow(non_camel_case_types)] | ||
#![deny(keyword_idents)] | ||
|
||
mod outer_mod { | ||
pub mod dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
pub struct dyn; | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
} | ||
} | ||
use outer_mod::dyn::dyn; | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
fn main() { | ||
match dyn { dyn => {} } | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
macro_defn::dyn(); | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
macro_defn::boxed(); | ||
} | ||
|
||
mod macro_defn { | ||
use super::Trait; | ||
|
||
macro_rules! dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
// Note that we do not lint nor fix occurrences under macros | ||
($dyn:ident) => { Box<dyn Trait> } | ||
} | ||
|
||
pub fn dyn() -> ::outer_mod::dyn::dyn { | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
::outer_mod::dyn::dyn | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
//~| ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
} | ||
|
||
|
||
|
||
pub fn boxed() -> dyn!( | ||
//~^ ERROR `dyn` is a keyword | ||
//~| WARN was previously accepted | ||
|
||
// Note that we do not lint nor fix occurrences under macros | ||
dyn | ||
) | ||
{ | ||
Box::new(10) | ||
} | ||
} | ||
|
||
pub trait Trait { } | ||
|
||
impl Trait for u32 { } |
133 changes: 133 additions & 0 deletions
133
src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
error: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:13:13 | ||
| | ||
LL | pub mod dyn { | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
note: lint level defined here | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:10:9 | ||
| | ||
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> | ||
|
||
error: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:16:20 | ||
| | ||
LL | pub struct dyn; | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:21:16 | ||
| | ||
LL | use outer_mod::dyn::dyn; | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:21:21 | ||
| | ||
LL | use outer_mod::dyn::dyn; | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:28:11 | ||
| | ||
LL | match dyn { dyn => {} } | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:28:17 | ||
| | ||
LL | match dyn { dyn => {} } | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:33:17 | ||
| | ||
LL | macro_defn::dyn(); | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:43:18 | ||
| | ||
LL | macro_rules! dyn { | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:51:12 | ||
| | ||
LL | pub fn dyn() -> ::outer_mod::dyn::dyn { | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:51:34 | ||
| | ||
LL | pub fn dyn() -> ::outer_mod::dyn::dyn { | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:51:39 | ||
| | ||
LL | pub fn dyn() -> ::outer_mod::dyn::dyn { | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:58:22 | ||
| | ||
LL | ::outer_mod::dyn::dyn | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:58:27 | ||
| | ||
LL | ::outer_mod::dyn::dyn | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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: `dyn` is a keyword in the 2018 edition | ||
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:67:23 | ||
| | ||
LL | pub fn boxed() -> dyn!( | ||
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` | ||
| | ||
= 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 14 previous errors | ||
|
24 changes: 24 additions & 0 deletions
24
src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// compile-pass | ||
|
||
// Under the 2015 edition with the keyword_idents lint, `dyn` is | ||
// not entirely acceptable as an identifier. | ||
// | ||
// We currently do not attempt to detect or fix uses of `dyn` as an | ||
// identifier under a macro. | ||
|
||
#![allow(non_camel_case_types)] | ||
#![deny(keyword_idents)] | ||
|
||
mod outer_mod { | ||
pub mod r#dyn { | ||
pub struct r#dyn; | ||
} | ||
} | ||
|
||
macro_rules! defn_has_dyn_idents { | ||
($arg:ident) => { ::outer_mod::dyn::dyn } | ||
} | ||
|
||
fn main() { | ||
defn_has_dyn_idents!(dyn); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Under the 2015 edition without the keyword_idents lint, `dyn` is | ||
// entirely acceptable as an identifier. | ||
|
||
// compile-pass | ||
|
||
#![allow(non_camel_case_types)] | ||
|
||
mod outer_mod { | ||
pub mod dyn { | ||
pub struct dyn; | ||
} | ||
} | ||
use outer_mod::dyn::dyn; | ||
|
||
fn main() { | ||
match dyn { dyn => {} } | ||
macro_defn::dyn(); | ||
} | ||
mod macro_defn { | ||
macro_rules! dyn { | ||
() => { ::outer_mod::dyn::dyn } | ||
} | ||
|
||
pub fn dyn() -> ::outer_mod::dyn::dyn { | ||
dyn!() | ||
} | ||
} |