]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
[rust.git] / src / test / ui / dyn-keyword / dyn-2015-idents-in-macros-unlinted.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2
3 // Under the 2015 edition with the keyword_idents lint, `dyn` is
4 // not entirely acceptable as an identifier.
5 //
6 // We currently do not attempt to detect or fix uses of `dyn` as an
7 // identifier under a macro.
8
9 #![allow(non_camel_case_types)]
10 #![deny(keyword_idents)]
11
12 mod outer_mod {
13     pub mod r#dyn {
14         pub struct r#dyn;
15     }
16 }
17
18 // Here we are illustrating that the current lint does not flag the
19 // occurrences of `dyn` in this macro definition; however, it
20 // certainly *could* (and it would be nice if it did), since these
21 // occurrences are not compatible with the 2018 edition's
22 // interpretation of `dyn` as a keyword.
23 macro_rules! defn_has_dyn_idents {
24     () => { ::outer_mod::dyn::dyn }
25 }
26
27 struct X;
28 trait Trait { fn hello(&self) { }}
29 impl Trait for X { }
30
31 macro_rules! tt_trait {
32     ($arg:tt) => { & $arg Trait }
33 }
34
35 macro_rules! id_trait {
36     ($id:ident) => { & $id Trait }
37 }
38
39 fn main() {
40     defn_has_dyn_idents!();
41
42     // Here we are illustrating that the current lint does not flag
43     // the occurrences of `dyn` in these macro invocations. It
44     // definitely should *not* flag the one in `tt_trait`, since that
45     // is expanding in a valid fashion to `&dyn Trait`.
46     //
47     // It is arguable whether it would be valid to flag the occurrence
48     // in `id_trait`, since that macro specifies that it takes an
49     // `ident` as its input.
50     fn f_tt(x: &X) -> tt_trait!(dyn) { x }
51     fn f_id(x: &X) -> id_trait!(dyn) { x }
52
53     let x = X;
54     f_tt(&x).hello();
55     f_id(&x).hello();
56 }