]>
Commit | Line | Data |
---|---|---|
83c7162d XL |
1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // aux-build:proc-macro-gates.rs | |
12 | // gate-test-proc_macro_non_items | |
13 | // gate-test-proc_macro_path_invoc | |
14 | // gate-test-proc_macro_mod line | |
15 | // gate-test-proc_macro_expr | |
16 | // gate-test-proc_macro_mod | |
94b46f34 | 17 | // gate-test-proc_macro_gen |
83c7162d XL |
18 | |
19 | #![feature(proc_macro, stmt_expr_attributes)] | |
20 | ||
21 | extern crate proc_macro_gates as foo; | |
22 | ||
23 | use foo::*; | |
24 | ||
25 | #[foo::a] //~ ERROR: paths of length greater than one | |
26 | fn _test() {} | |
27 | ||
28 | fn _test_inner() { | |
29 | #![a] // OK | |
30 | } | |
31 | ||
32 | #[a] //~ ERROR: custom attributes cannot be applied to modules | |
94b46f34 | 33 | //~| ERROR: procedural macros cannot expand to modules |
83c7162d XL |
34 | mod _test2 {} |
35 | ||
36 | mod _test2_inner { | |
37 | #![a] //~ ERROR: custom attributes cannot be applied to modules | |
94b46f34 | 38 | //~| ERROR: procedural macros cannot expand to modules |
83c7162d XL |
39 | } |
40 | ||
41 | #[a = y] //~ ERROR: must only be followed by a delimiter token | |
42 | fn _test3() {} | |
43 | ||
44 | #[a = ] //~ ERROR: must only be followed by a delimiter token | |
45 | fn _test4() {} | |
46 | ||
47 | #[a () = ] //~ ERROR: must only be followed by a delimiter token | |
48 | fn _test5() {} | |
49 | ||
50 | fn attrs() { | |
51 | // Statement, item | |
52 | #[a] // OK | |
53 | struct S; | |
54 | ||
55 | // Statement, macro | |
56 | #[a] //~ ERROR: custom attributes cannot be applied to statements | |
57 | println!(); | |
58 | ||
59 | // Statement, semi | |
60 | #[a] //~ ERROR: custom attributes cannot be applied to statements | |
61 | S; | |
62 | ||
63 | // Statement, local | |
64 | #[a] //~ ERROR: custom attributes cannot be applied to statements | |
65 | let _x = 2; | |
66 | ||
67 | // Expr | |
68 | let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions | |
69 | ||
70 | // Opt expr | |
71 | let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions | |
72 | ||
73 | // Expr macro | |
74 | let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions | |
75 | } | |
76 | ||
77 | fn main() { | |
78 | let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types | |
79 | if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns | |
80 | ||
81 | m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements | |
82 | m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements | |
83 | ||
84 | let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions | |
85 | let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions | |
86 | } |