]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-5067.rs
Rollup merge of #62337 - Mark-Simulacrum:fix-cpu-usage-script, r=alexcrichton
[rust.git] / src / test / ui / issues / issue-5067.rs
1 #![allow(unused_macros)]
2
3 // Tests that repetition matchers cannot match the empty token tree (since that would be
4 // ambiguous).
5
6 // edition:2018
7
8 macro_rules! foo {
9     ( $()* ) => {};
10     //~^ ERROR repetition matches empty token tree
11     ( $()+ ) => {};
12     //~^ ERROR repetition matches empty token tree
13     ( $()? ) => {};
14     //~^ ERROR repetition matches empty token tree
15     ( $(),* ) => {}; // PASS
16     ( $(),+ ) => {}; // PASS
17     // `?` cannot have a separator...
18     ( [$()*] ) => {};
19     //~^ ERROR repetition matches empty token tree
20     ( [$()+] ) => {};
21     //~^ ERROR repetition matches empty token tree
22     ( [$()?] ) => {};
23     //~^ ERROR repetition matches empty token tree
24     ( [$(),*] ) => {}; // PASS
25     ( [$(),+] ) => {}; // PASS
26     // `?` cannot have a separator...
27     ( $($()* $(),* $(a)* $(a),* )* ) => {};
28     //~^ ERROR repetition matches empty token tree
29     ( $($()* $(),* $(a)* $(a),* )+ ) => {};
30     //~^ ERROR repetition matches empty token tree
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
39     ( $(a     $(),* $(a)* $(a),* )* ) => {}; // PASS
40     ( $($(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
46
47     ( $(a $()+)* ) => {};
48     //~^ ERROR repetition matches empty token tree
49     ( $(a $()*)+ ) => {};
50     //~^ ERROR repetition matches empty token tree
51     ( $(a $()+)? ) => {};
52     //~^ ERROR repetition matches empty token tree
53     ( $(a $()?)+ ) => {};
54     //~^ ERROR repetition matches empty token tree
55 }
56
57 // --- Original Issue --- //
58
59 macro_rules! make_vec {
60     (a $e1:expr $($(, a $e2:expr)*)*) => ([$e1 $($(, $e2)*)*]);
61     //~^ ERROR repetition matches empty token tree
62 }
63
64 fn main() {
65     let _ = make_vec![a 1, a 2, a 3];
66 }
67
68 // --- Minified Issue --- //
69
70 macro_rules! m {
71     ( $()* ) => {};
72     //~^ ERROR repetition matches empty token tree
73 }
74
75 m!();