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