]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-5067.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / issues / issue-5067.rs
CommitLineData
7cac9316
XL
1#![allow(unused_macros)]
2
9fa01778
XL
3// Tests that repetition matchers cannot match the empty token tree (since that would be
4// ambiguous).
5
6// edition:2018
7
9e0c209e
SL
8macro_rules! foo {
9 ( $()* ) => {};
10 //~^ ERROR repetition matches empty token tree
11 ( $()+ ) => {};
12 //~^ ERROR repetition matches empty token tree
9fa01778
XL
13 ( $()? ) => {};
14 //~^ ERROR repetition matches empty token tree
9e0c209e
SL
15 ( $(),* ) => {}; // PASS
16 ( $(),+ ) => {}; // PASS
9fa01778 17 // `?` cannot have a separator...
9e0c209e
SL
18 ( [$()*] ) => {};
19 //~^ ERROR repetition matches empty token tree
20 ( [$()+] ) => {};
21 //~^ ERROR repetition matches empty token tree
9fa01778
XL
22 ( [$()?] ) => {};
23 //~^ ERROR repetition matches empty token tree
9e0c209e
SL
24 ( [$(),*] ) => {}; // PASS
25 ( [$(),+] ) => {}; // PASS
9fa01778 26 // `?` cannot have a separator...
9e0c209e
SL
27 ( $($()* $(),* $(a)* $(a),* )* ) => {};
28 //~^ ERROR repetition matches empty token tree
29 ( $($()* $(),* $(a)* $(a),* )+ ) => {};
30 //~^ ERROR repetition matches empty token tree
9fa01778
XL
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
9e0c209e
SL
39 ( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
40 ( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
9fa01778
XL
41 ( $($(a)+ $(),* $(a)* $(a),* )? ) => {}; // PASS
42
43 ( $(a $(),* $(a)? $(a),* )* ) => {}; // PASS
44 ( $($(a)+ $(),* $(a)? $(a),* )+ ) => {}; // PASS
45 ( $($(a)+ $(),* $(a)? $(a),* )? ) => {}; // PASS
9e0c209e
SL
46
47 ( $(a $()+)* ) => {};
48 //~^ ERROR repetition matches empty token tree
49 ( $(a $()*)+ ) => {};
50 //~^ ERROR repetition matches empty token tree
9fa01778
XL
51 ( $(a $()+)? ) => {};
52 //~^ ERROR repetition matches empty token tree
53 ( $(a $()?)+ ) => {};
54 //~^ ERROR repetition matches empty token tree
9e0c209e
SL
55}
56
e1599b0c 57// Original Issue
9e0c209e
SL
58
59macro_rules! make_vec {
60 (a $e1:expr $($(, a $e2:expr)*)*) => ([$e1 $($(, $e2)*)*]);
61 //~^ ERROR repetition matches empty token tree
62}
63
64fn main() {
c30ab7b3 65 let _ = make_vec![a 1, a 2, a 3];
9e0c209e
SL
66}
67
e1599b0c 68// Minified Issue
9e0c209e
SL
69
70macro_rules! m {
9fa01778 71 ( $()* ) => {};
9e0c209e
SL
72 //~^ ERROR repetition matches empty token tree
73}
74
75m!();