Skip to content
Permalink
Browse files

Some tests illustrating where the revised lint does and does not apply.

  • Loading branch information...
pnkfelix committed Mar 27, 2019
1 parent 6046f4a commit 6d7e5df3d92fcb5f67a790dfc56acec2a33170d3
@@ -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 { }
@@ -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 { }
@@ -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

@@ -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);
}
@@ -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!()
}
}

0 comments on commit 6d7e5df

Please sign in to comment.
You can’t perform that action at this time.