]> git.proxmox.com Git - rustc.git/blob - src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.rs
New upstream version 1.55.0+dfsg1
[rustc.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 // edition:2015
8 // run-rustfix
9
10 #![allow(non_camel_case_types)]
11 #![deny(keyword_idents)]
12
13 mod outer_mod {
14 pub mod dyn {
15 //~^ ERROR `dyn` is a keyword
16 //~| WARN this is accepted in the current edition
17 pub struct dyn;
18 //~^ ERROR `dyn` is a keyword
19 //~| WARN this is accepted in the current edition
20 }
21 }
22 use outer_mod::dyn::dyn;
23 //~^ ERROR `dyn` is a keyword
24 //~| WARN this is accepted in the current edition
25 //~| ERROR `dyn` is a keyword
26 //~| WARN this is accepted in the current edition
27
28 fn main() {
29 match dyn { dyn => {} }
30 //~^ ERROR `dyn` is a keyword
31 //~| WARN this is accepted in the current edition
32 //~| ERROR `dyn` is a keyword
33 //~| WARN this is accepted in the current edition
34 macro_defn::dyn();
35 //~^ ERROR `dyn` is a keyword
36 //~| WARN this is accepted in the current edition
37
38 macro_defn::boxed();
39 }
40
41 mod macro_defn {
42 use super::Trait;
43
44 macro_rules! dyn {
45 //~^ ERROR `dyn` is a keyword
46 //~| WARN this is accepted in the current edition
47
48 // Note that we do not lint nor fix occurrences under macros
49 ($dyn:tt) => { (Box<dyn Trait>, Box<$dyn Trait>) }
50 }
51
52 pub fn dyn() -> ::outer_mod::dyn::dyn {
53 //~^ ERROR `dyn` is a keyword
54 //~| WARN this is accepted in the current edition
55 //~| ERROR `dyn` is a keyword
56 //~| WARN this is accepted in the current edition
57 //~| ERROR `dyn` is a keyword
58 //~| WARN this is accepted in the current edition
59 ::outer_mod::dyn::dyn
60 //~^ ERROR `dyn` is a keyword
61 //~| WARN this is accepted in the current edition
62 //~| ERROR `dyn` is a keyword
63 //~| WARN this is accepted in the current edition
64 }
65
66
67
68 pub fn boxed() -> dyn!(
69 //~^ ERROR `dyn` is a keyword
70 //~| WARN this is accepted in the current edition
71
72 // Note that we do not lint nor fix occurrences under macros
73 dyn
74 )
75 {
76 (Box::new(1), Box::new(2))
77 }
78 }
79
80 pub trait Trait { }
81
82 impl Trait for u32 { }