Skip to content

Commit dabe86d

Browse files
committed
update/add tests
1 parent 6046be4 commit dabe86d

File tree

3 files changed

+183
-8
lines changed

3 files changed

+183
-8
lines changed

src/test/ui/issues/issue-5067.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,59 @@
11
#![allow(unused_macros)]
22

3+
// Tests that repetition matchers cannot match the empty token tree (since that would be
4+
// ambiguous).
5+
6+
// edition:2018
7+
38
macro_rules! foo {
49
( $()* ) => {};
510
//~^ ERROR repetition matches empty token tree
611
( $()+ ) => {};
712
//~^ ERROR repetition matches empty token tree
8-
13+
( $()? ) => {};
14+
//~^ ERROR repetition matches empty token tree
915
( $(),* ) => {}; // PASS
1016
( $(),+ ) => {}; // PASS
11-
17+
// `?` cannot have a separator...
1218
( [$()*] ) => {};
1319
//~^ ERROR repetition matches empty token tree
1420
( [$()+] ) => {};
1521
//~^ ERROR repetition matches empty token tree
16-
22+
( [$()?] ) => {};
23+
//~^ ERROR repetition matches empty token tree
1724
( [$(),*] ) => {}; // PASS
1825
( [$(),+] ) => {}; // PASS
19-
26+
// `?` cannot have a separator...
2027
( $($()* $(),* $(a)* $(a),* )* ) => {};
2128
//~^ ERROR repetition matches empty token tree
2229
( $($()* $(),* $(a)* $(a),* )+ ) => {};
2330
//~^ ERROR repetition matches empty token tree
24-
31+
( $($()* $(),* $(a)* $(a),* )? ) => {};
32+
//~^ ERROR repetition matches empty token tree
33+
( $($()? $(),* $(a)? $(a),* )* ) => {};
34+
//~^ ERROR repetition matches empty token tree
35+
( $($()? $(),* $(a)? $(a),* )+ ) => {};
36+
//~^ ERROR repetition matches empty token tree
37+
( $($()? $(),* $(a)? $(a),* )? ) => {};
38+
//~^ ERROR repetition matches empty token tree
2539
( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
2640
( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
41+
( $($(a)+ $(),* $(a)* $(a),* )? ) => {}; // PASS
42+
43+
( $(a $(),* $(a)? $(a),* )* ) => {}; // PASS
44+
( $($(a)+ $(),* $(a)? $(a),* )+ ) => {}; // PASS
45+
( $($(a)+ $(),* $(a)? $(a),* )? ) => {}; // PASS
2746

2847
( $(a $()+)* ) => {};
2948
//~^ ERROR repetition matches empty token tree
3049
( $(a $()*)+ ) => {};
3150
//~^ ERROR repetition matches empty token tree
51+
( $(a $()+)? ) => {};
52+
//~^ ERROR repetition matches empty token tree
53+
( $(a $()?)+ ) => {};
54+
//~^ ERROR repetition matches empty token tree
3255
}
3356

34-
3557
// --- Original Issue --- //
3658

3759
macro_rules! make_vec {
@@ -43,11 +65,10 @@ fn main() {
4365
let _ = make_vec![a 1, a 2, a 3];
4466
}
4567

46-
4768
// --- Minified Issue --- //
4869

4970
macro_rules! m {
50-
( $()* ) => {}
71+
( $()* ) => {};
5172
//~^ ERROR repetition matches empty token tree
5273
}
5374

src/test/ui/issues/issue-57597.rs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Regression test for #57597.
2+
//
3+
// Make sure that nested matchers work correctly rather than causing an infinite loop or crash.
4+
5+
// edition:2018
6+
7+
macro_rules! foo1 {
8+
($($($i:ident)?)+) => {};
9+
//~^ ERROR repetition matches empty token tree
10+
}
11+
12+
macro_rules! foo2 {
13+
($($($i:ident)?)*) => {};
14+
//~^ ERROR repetition matches empty token tree
15+
}
16+
17+
macro_rules! foo3 {
18+
($($($i:ident)?)?) => {};
19+
//~^ ERROR repetition matches empty token tree
20+
}
21+
22+
macro_rules! foo4 {
23+
($($($($i:ident)?)?)?) => {};
24+
//~^ ERROR repetition matches empty token tree
25+
}
26+
27+
macro_rules! foo5 {
28+
($($($($i:ident)*)?)?) => {};
29+
//~^ ERROR repetition matches empty token tree
30+
}
31+
32+
macro_rules! foo6 {
33+
($($($($i:ident)?)*)?) => {};
34+
//~^ ERROR repetition matches empty token tree
35+
}
36+
37+
macro_rules! foo7 {
38+
($($($($i:ident)?)?)*) => {};
39+
//~^ ERROR repetition matches empty token tree
40+
}
41+
42+
macro_rules! foo8 {
43+
($($($($i:ident)*)*)?) => {};
44+
//~^ ERROR repetition matches empty token tree
45+
}
46+
47+
macro_rules! foo9 {
48+
($($($($i:ident)?)*)*) => {};
49+
//~^ ERROR repetition matches empty token tree
50+
}
51+
52+
macro_rules! foo10 {
53+
($($($($i:ident)?)*)+) => {};
54+
//~^ ERROR repetition matches empty token tree
55+
}
56+
57+
macro_rules! foo11 {
58+
($($($($i:ident)+)?)*) => {};
59+
//~^ ERROR repetition matches empty token tree
60+
}
61+
62+
macro_rules! foo12 {
63+
($($($($i:ident)+)*)?) => {};
64+
//~^ ERROR repetition matches empty token tree
65+
}
66+
67+
fn main() {
68+
foo1!();
69+
foo2!();
70+
foo3!();
71+
foo4!();
72+
foo5!();
73+
foo6!();
74+
foo7!();
75+
foo8!();
76+
foo9!();
77+
foo10!();
78+
foo11!();
79+
foo12!();
80+
}

src/test/ui/issues/issue-57597.stderr

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error: repetition matches empty token tree
2+
--> $DIR/issue-57597.rs:8:7
3+
|
4+
LL | ($($($i:ident)?)+) => {};
5+
| ^^^^^^^^^^^^^^
6+
7+
error: repetition matches empty token tree
8+
--> $DIR/issue-57597.rs:13:7
9+
|
10+
LL | ($($($i:ident)?)*) => {};
11+
| ^^^^^^^^^^^^^^
12+
13+
error: repetition matches empty token tree
14+
--> $DIR/issue-57597.rs:18:7
15+
|
16+
LL | ($($($i:ident)?)?) => {};
17+
| ^^^^^^^^^^^^^^
18+
19+
error: repetition matches empty token tree
20+
--> $DIR/issue-57597.rs:23:7
21+
|
22+
LL | ($($($($i:ident)?)?)?) => {};
23+
| ^^^^^^^^^^^^^^^^^^
24+
25+
error: repetition matches empty token tree
26+
--> $DIR/issue-57597.rs:28:7
27+
|
28+
LL | ($($($($i:ident)*)?)?) => {};
29+
| ^^^^^^^^^^^^^^^^^^
30+
31+
error: repetition matches empty token tree
32+
--> $DIR/issue-57597.rs:33:7
33+
|
34+
LL | ($($($($i:ident)?)*)?) => {};
35+
| ^^^^^^^^^^^^^^^^^^
36+
37+
error: repetition matches empty token tree
38+
--> $DIR/issue-57597.rs:38:7
39+
|
40+
LL | ($($($($i:ident)?)?)*) => {};
41+
| ^^^^^^^^^^^^^^^^^^
42+
43+
error: repetition matches empty token tree
44+
--> $DIR/issue-57597.rs:43:7
45+
|
46+
LL | ($($($($i:ident)*)*)?) => {};
47+
| ^^^^^^^^^^^^^^^^^^
48+
49+
error: repetition matches empty token tree
50+
--> $DIR/issue-57597.rs:48:7
51+
|
52+
LL | ($($($($i:ident)?)*)*) => {};
53+
| ^^^^^^^^^^^^^^^^^^
54+
55+
error: repetition matches empty token tree
56+
--> $DIR/issue-57597.rs:53:7
57+
|
58+
LL | ($($($($i:ident)?)*)+) => {};
59+
| ^^^^^^^^^^^^^^^^^^
60+
61+
error: repetition matches empty token tree
62+
--> $DIR/issue-57597.rs:58:7
63+
|
64+
LL | ($($($($i:ident)+)?)*) => {};
65+
| ^^^^^^^^^^^^^^^^^^
66+
67+
error: repetition matches empty token tree
68+
--> $DIR/issue-57597.rs:63:7
69+
|
70+
LL | ($($($($i:ident)+)*)?) => {};
71+
| ^^^^^^^^^^^^^^^^^^
72+
73+
error: aborting due to 12 previous errors
74+

0 commit comments

Comments
 (0)