Skip to content

Commit 0a6e91b

Browse files
committed
Add a few more tests for proc macro feature gating
1 parent 79252ff commit 0a6e91b

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs

+42-13
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ use foo::*;
2424
#[foo::a] //~ ERROR: paths of length greater than one
2525
fn _test() {}
2626

27+
fn _test_inner() {
28+
#![a] // OK
29+
}
30+
2731
#[a] //~ ERROR: custom attributes cannot be applied to modules
2832
mod _test2 {}
2933

34+
mod _test2_inner {
35+
#![a] //~ ERROR: custom attributes cannot be applied to modules
36+
}
37+
3038
#[a = y] //~ ERROR: must only be followed by a delimiter token
3139
fn _test3() {}
3240

@@ -36,19 +44,40 @@ fn _test4() {}
3644
#[a () = ] //~ ERROR: must only be followed by a delimiter token
3745
fn _test5() {}
3846

39-
fn main() {
47+
fn attrs() {
48+
// Statement, item
49+
#[a] // OK
50+
struct S;
51+
52+
// Statement, macro
53+
#[a] //~ ERROR: custom attributes cannot be applied to statements
54+
println!();
55+
56+
// Statement, semi
57+
#[a] //~ ERROR: custom attributes cannot be applied to statements
58+
S;
59+
60+
// Statement, local
4061
#[a] //~ ERROR: custom attributes cannot be applied to statements
4162
let _x = 2;
42-
let _x = #[a] 2;
43-
//~^ ERROR: custom attributes cannot be applied to expressions
44-
45-
let _x: m!(u32) = 3;
46-
//~^ ERROR: procedural macros cannot be expanded to types
47-
if let m!(Some(_x)) = Some(3) {
48-
//~^ ERROR: procedural macros cannot be expanded to patterns
49-
}
50-
let _x = m!(3);
51-
//~^ ERROR: procedural macros cannot be expanded to expressions
52-
m!(let _x = 3;);
53-
//~^ ERROR: procedural macros cannot be expanded to statements
63+
64+
// Expr
65+
let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions
66+
67+
// Opt expr
68+
let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions
69+
70+
// Expr macro
71+
let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions
72+
}
73+
74+
fn main() {
75+
let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
76+
if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns
77+
78+
m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements
79+
m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements
80+
81+
let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions
82+
let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions
5483
}

0 commit comments

Comments
 (0)