]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
[rust.git] / src / test / ui / dyn-keyword / dyn-2015-edition-keyword-ident-lint.rs
1 // Under the 2015 edition with the keyword_idents lint, `dyn` is not
2 // entirely acceptable as an identifier. We currently do not attempt
3 // to detect or fix uses of `dyn` under a macro. Since we are testing
4 // this file via `rustfix`, we want the rustfix output to be
5 // compilable; so the macros here carefully use `dyn` "correctly."
6
7 // run-rustfix
8
9 #![allow(non_camel_case_types)]
10 #![deny(keyword_idents)]
11
12 mod outer_mod {
13     pub mod dyn {
14 //~^ ERROR `dyn` is a keyword
15 //~| WARN was previously accepted
16         pub struct dyn;
17 //~^ ERROR `dyn` is a keyword
18 //~| WARN was previously accepted
19     }
20 }
21 use outer_mod::dyn::dyn;
22 //~^ ERROR `dyn` is a keyword
23 //~| WARN was previously accepted
24 //~| ERROR `dyn` is a keyword
25 //~| WARN was previously accepted
26
27 fn main() {
28     match dyn { dyn => {} }
29 //~^ ERROR `dyn` is a keyword
30 //~| WARN was previously accepted
31 //~| ERROR `dyn` is a keyword
32 //~| WARN was previously accepted
33     macro_defn::dyn();
34 //~^ ERROR `dyn` is a keyword
35 //~| WARN was previously accepted
36
37     macro_defn::boxed();
38 }
39
40 mod macro_defn {
41     use super::Trait;
42
43     macro_rules! dyn {
44 //~^ ERROR `dyn` is a keyword
45 //~| WARN was previously accepted
46
47         // Note that we do not lint nor fix occurrences under macros
48         ($dyn:tt) => { (Box<dyn Trait>, Box<$dyn Trait>) }
49     }
50
51     pub fn dyn() -> ::outer_mod::dyn::dyn {
52 //~^ ERROR `dyn` is a keyword
53 //~| WARN was previously accepted
54 //~| ERROR `dyn` is a keyword
55 //~| WARN was previously accepted
56 //~| ERROR `dyn` is a keyword
57 //~| WARN was previously accepted
58         ::outer_mod::dyn::dyn
59 //~^ ERROR `dyn` is a keyword
60 //~| WARN was previously accepted
61 //~| ERROR `dyn` is a keyword
62 //~| WARN was previously accepted
63     }
64
65
66
67     pub fn boxed() -> dyn!(
68         //~^ ERROR `dyn` is a keyword
69         //~| WARN was previously accepted
70
71             // Note that we do not lint nor fix occurrences under macros
72             dyn
73     )
74     {
75         (Box::new(1), Box::new(2))
76     }
77 }
78
79 pub trait Trait { }
80
81 impl Trait for u32 { }