]> git.proxmox.com Git - rustc.git/blame - src/test/ui/dyn-keyword/dyn-2015-idents-in-macros-unlinted.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / dyn-keyword / dyn-2015-idents-in-macros-unlinted.rs
CommitLineData
532ac7d7
XL
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.
136023e0
XL
6//
7// check-pass
8// edition:2015
532ac7d7
XL
9
10#![allow(non_camel_case_types)]
11#![deny(keyword_idents)]
12
13mod outer_mod {
14 pub mod r#dyn {
15 pub struct r#dyn;
16 }
17}
18
19// Here we are illustrating that the current lint does not flag the
20// occurrences of `dyn` in this macro definition; however, it
21// certainly *could* (and it would be nice if it did), since these
22// occurrences are not compatible with the 2018 edition's
23// interpretation of `dyn` as a keyword.
24macro_rules! defn_has_dyn_idents {
25 () => { ::outer_mod::dyn::dyn }
26}
27
28struct X;
29trait Trait { fn hello(&self) { }}
30impl Trait for X { }
31
32macro_rules! tt_trait {
33 ($arg:tt) => { & $arg Trait }
34}
35
36macro_rules! id_trait {
37 ($id:ident) => { & $id Trait }
38}
39
40fn main() {
41 defn_has_dyn_idents!();
42
43 // Here we are illustrating that the current lint does not flag
44 // the occurrences of `dyn` in these macro invocations. It
45 // definitely should *not* flag the one in `tt_trait`, since that
46 // is expanding in a valid fashion to `&dyn Trait`.
47 //
48 // It is arguable whether it would be valid to flag the occurrence
49 // in `id_trait`, since that macro specifies that it takes an
50 // `ident` as its input.
51 fn f_tt(x: &X) -> tt_trait!(dyn) { x }
52 fn f_id(x: &X) -> id_trait!(dyn) { x }
53
54 let x = X;
55 f_tt(&x).hello();
56 f_id(&x).hello();
57}