Skip to content

Commit 05c5b87

Browse files
committed
mbe: Add parsing tests for unsafe macro rules
1 parent 6bff1ab commit 05c5b87

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

tests/ui/parser/macro/bad-macro-definition.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ macro_rules! e { {} }
2020

2121
macro_rules! f {}
2222
//~^ ERROR: macros must contain at least one rule
23+
24+
macro_rules! g { unsafe {} => {} }
25+
//~^ ERROR: `unsafe` is only supported on `attr` rules

tests/ui/parser/macro/bad-macro-definition.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ error: macros must contain at least one rule
5252
LL | macro_rules! f {}
5353
| ^^^^^^^^^^^^^^^^^
5454

55-
error: aborting due to 9 previous errors
55+
error: `unsafe` is only supported on `attr` rules
56+
--> $DIR/bad-macro-definition.rs:24:18
57+
|
58+
LL | macro_rules! g { unsafe {} => {} }
59+
| ^^^^^^
60+
61+
error: aborting due to 10 previous errors
5662

tests/ui/parser/macro/macro-attr-bad.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ macro_rules! attr_incomplete_3 { attr() {} }
1313
macro_rules! attr_incomplete_4 { attr() {} => }
1414
//~^ ERROR macro definition ended unexpectedly
1515

16+
macro_rules! attr_incomplete_5 { unsafe }
17+
//~^ ERROR macro definition ended unexpectedly
18+
19+
macro_rules! attr_incomplete_6 { unsafe attr }
20+
//~^ ERROR macro definition ended unexpectedly
21+
1622
macro_rules! attr_noparens_1 { attr{} {} => {} }
1723
//~^ ERROR `attr` rule argument matchers require parentheses
1824

tests/ui/parser/macro/macro-attr-bad.stderr

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ error: macro definition ended unexpectedly
2222
LL | macro_rules! attr_incomplete_4 { attr() {} => }
2323
| ^ expected right-hand side of macro rule
2424

25+
error: macro definition ended unexpectedly
26+
--> $DIR/macro-attr-bad.rs:16:40
27+
|
28+
LL | macro_rules! attr_incomplete_5 { unsafe }
29+
| ^ expected `attr`
30+
31+
error: macro definition ended unexpectedly
32+
--> $DIR/macro-attr-bad.rs:19:45
33+
|
34+
LL | macro_rules! attr_incomplete_6 { unsafe attr }
35+
| ^ expected macro attr args
36+
2537
error: `attr` rule argument matchers require parentheses
26-
--> $DIR/macro-attr-bad.rs:16:36
38+
--> $DIR/macro-attr-bad.rs:22:36
2739
|
2840
LL | macro_rules! attr_noparens_1 { attr{} {} => {} }
2941
| ^^
@@ -35,7 +47,7 @@ LL + macro_rules! attr_noparens_1 { attr() {} => {} }
3547
|
3648

3749
error: `attr` rule argument matchers require parentheses
38-
--> $DIR/macro-attr-bad.rs:19:36
50+
--> $DIR/macro-attr-bad.rs:25:36
3951
|
4052
LL | macro_rules! attr_noparens_2 { attr[] {} => {} }
4153
| ^^
@@ -47,34 +59,34 @@ LL + macro_rules! attr_noparens_2 { attr() {} => {} }
4759
|
4860

4961
error: invalid macro matcher; matchers must be contained in balanced delimiters
50-
--> $DIR/macro-attr-bad.rs:22:37
62+
--> $DIR/macro-attr-bad.rs:28:37
5163
|
5264
LL | macro_rules! attr_noparens_3 { attr _ {} => {} }
5365
| ^
5466

5567
error: duplicate matcher binding
56-
--> $DIR/macro-attr-bad.rs:25:52
68+
--> $DIR/macro-attr-bad.rs:31:52
5769
|
5870
LL | macro_rules! attr_dup_matcher_1 { attr() {$x:ident $x:ident} => {} }
5971
| -------- ^^^^^^^^ duplicate binding
6072
| |
6173
| previous binding
6274

6375
error: duplicate matcher binding
64-
--> $DIR/macro-attr-bad.rs:28:49
76+
--> $DIR/macro-attr-bad.rs:34:49
6577
|
6678
LL | macro_rules! attr_dup_matcher_2 { attr($x:ident $x:ident) {} => {} }
6779
| -------- ^^^^^^^^ duplicate binding
6880
| |
6981
| previous binding
7082

7183
error: duplicate matcher binding
72-
--> $DIR/macro-attr-bad.rs:31:51
84+
--> $DIR/macro-attr-bad.rs:37:51
7385
|
7486
LL | macro_rules! attr_dup_matcher_3 { attr($x:ident) {$x:ident} => {} }
7587
| -------- ^^^^^^^^ duplicate binding
7688
| |
7789
| previous binding
7890

79-
error: aborting due to 10 previous errors
91+
error: aborting due to 12 previous errors
8092

tests/ui/parser/macro/macro-derive-bad.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ macro_rules! derive_dup_matcher { derive() {$x:ident $x:ident} => {} }
4141
//~^ ERROR duplicate matcher binding
4242
//~| NOTE duplicate binding
4343
//~| NOTE previous binding
44+
45+
macro_rules! derive_unsafe { unsafe derive() {} => {} }
46+
//~^ ERROR `unsafe` is only supported on `attr` rules

tests/ui/parser/macro/macro-derive-bad.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,11 @@ LL | macro_rules! derive_dup_matcher { derive() {$x:ident $x:ident} => {} }
8686
| |
8787
| previous binding
8888

89-
error: aborting due to 12 previous errors
89+
error: `unsafe` is only supported on `attr` rules
90+
--> $DIR/macro-derive-bad.rs:45:30
91+
|
92+
LL | macro_rules! derive_unsafe { unsafe derive() {} => {} }
93+
| ^^^^^^
94+
95+
error: aborting due to 13 previous errors
9096

0 commit comments

Comments
 (0)