rust/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.fixed
Felix S. Klock II f043d2da65 Revise test slightly so that dyn in macro invocation *must* be parsed as keyword in test.
Back-story: After reflection this morning, I realized that the
previous form of this test would allow the macro invocation to treat
the `dyn` input as a raw-identifier rather than a keyword, and since
the input was discarded by that version of the macro, the test would
pass despite the detail that the input `dyn` should not have been
parsed as a raw-identifier.

This revision fixes that oversight, by actually *using* the macro
input to construct a `Box<dyn Trait>` type.
2019-03-28 12:49:50 +01:00

82 lines
2.0 KiB
Rust

// 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:tt) => { (Box<dyn Trait>, 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(1), Box::new(2))
}
}
pub trait Trait { }
impl Trait for u32 { }