update/add tests
This commit is contained in:
parent
6046be42ab
commit
dabe86db44
@ -1,37 +1,59 @@
|
|||||||
#![allow(unused_macros)]
|
#![allow(unused_macros)]
|
||||||
|
|
||||||
|
// Tests that repetition matchers cannot match the empty token tree (since that would be
|
||||||
|
// ambiguous).
|
||||||
|
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
macro_rules! foo {
|
macro_rules! foo {
|
||||||
( $()* ) => {};
|
( $()* ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
( $()+ ) => {};
|
( $()+ ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $()? ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
( $(),* ) => {}; // PASS
|
( $(),* ) => {}; // PASS
|
||||||
( $(),+ ) => {}; // PASS
|
( $(),+ ) => {}; // PASS
|
||||||
|
// `?` cannot have a separator...
|
||||||
( [$()*] ) => {};
|
( [$()*] ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
( [$()+] ) => {};
|
( [$()+] ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( [$()?] ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
( [$(),*] ) => {}; // PASS
|
( [$(),*] ) => {}; // PASS
|
||||||
( [$(),+] ) => {}; // PASS
|
( [$(),+] ) => {}; // PASS
|
||||||
|
// `?` cannot have a separator...
|
||||||
( $($()* $(),* $(a)* $(a),* )* ) => {};
|
( $($()* $(),* $(a)* $(a),* )* ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
( $($()* $(),* $(a)* $(a),* )+ ) => {};
|
( $($()* $(),* $(a)* $(a),* )+ ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $($()* $(),* $(a)* $(a),* )? ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $($()? $(),* $(a)? $(a),* )* ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $($()? $(),* $(a)? $(a),* )+ ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $($()? $(),* $(a)? $(a),* )? ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
|
( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
|
||||||
( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
|
( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
|
||||||
|
( $($(a)+ $(),* $(a)* $(a),* )? ) => {}; // PASS
|
||||||
|
|
||||||
|
( $(a $(),* $(a)? $(a),* )* ) => {}; // PASS
|
||||||
|
( $($(a)+ $(),* $(a)? $(a),* )+ ) => {}; // PASS
|
||||||
|
( $($(a)+ $(),* $(a)? $(a),* )? ) => {}; // PASS
|
||||||
|
|
||||||
( $(a $()+)* ) => {};
|
( $(a $()+)* ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
( $(a $()*)+ ) => {};
|
( $(a $()*)+ ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $(a $()+)? ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
( $(a $()?)+ ) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- Original Issue --- //
|
// --- Original Issue --- //
|
||||||
|
|
||||||
macro_rules! make_vec {
|
macro_rules! make_vec {
|
||||||
@ -43,11 +65,10 @@ fn main() {
|
|||||||
let _ = make_vec![a 1, a 2, a 3];
|
let _ = make_vec![a 1, a 2, a 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- Minified Issue --- //
|
// --- Minified Issue --- //
|
||||||
|
|
||||||
macro_rules! m {
|
macro_rules! m {
|
||||||
( $()* ) => {}
|
( $()* ) => {};
|
||||||
//~^ ERROR repetition matches empty token tree
|
//~^ ERROR repetition matches empty token tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
80
src/test/ui/issues/issue-57597.rs
Normal file
80
src/test/ui/issues/issue-57597.rs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Regression test for #57597.
|
||||||
|
//
|
||||||
|
// Make sure that nested matchers work correctly rather than causing an infinite loop or crash.
|
||||||
|
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
macro_rules! foo1 {
|
||||||
|
($($($i:ident)?)+) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo2 {
|
||||||
|
($($($i:ident)?)*) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo3 {
|
||||||
|
($($($i:ident)?)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo4 {
|
||||||
|
($($($($i:ident)?)?)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo5 {
|
||||||
|
($($($($i:ident)*)?)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo6 {
|
||||||
|
($($($($i:ident)?)*)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo7 {
|
||||||
|
($($($($i:ident)?)?)*) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo8 {
|
||||||
|
($($($($i:ident)*)*)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo9 {
|
||||||
|
($($($($i:ident)?)*)*) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo10 {
|
||||||
|
($($($($i:ident)?)*)+) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo11 {
|
||||||
|
($($($($i:ident)+)?)*) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo12 {
|
||||||
|
($($($($i:ident)+)*)?) => {};
|
||||||
|
//~^ ERROR repetition matches empty token tree
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo1!();
|
||||||
|
foo2!();
|
||||||
|
foo3!();
|
||||||
|
foo4!();
|
||||||
|
foo5!();
|
||||||
|
foo6!();
|
||||||
|
foo7!();
|
||||||
|
foo8!();
|
||||||
|
foo9!();
|
||||||
|
foo10!();
|
||||||
|
foo11!();
|
||||||
|
foo12!();
|
||||||
|
}
|
74
src/test/ui/issues/issue-57597.stderr
Normal file
74
src/test/ui/issues/issue-57597.stderr
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:8:7
|
||||||
|
|
|
||||||
|
LL | ($($($i:ident)?)+) => {};
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:13:7
|
||||||
|
|
|
||||||
|
LL | ($($($i:ident)?)*) => {};
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:18:7
|
||||||
|
|
|
||||||
|
LL | ($($($i:ident)?)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:23:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)?)?)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:28:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)*)?)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:33:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)?)*)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:38:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)?)?)*) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:43:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)*)*)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:48:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)?)*)*) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:53:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)?)*)+) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:58:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)+)?)*) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: repetition matches empty token tree
|
||||||
|
--> $DIR/issue-57597.rs:63:7
|
||||||
|
|
|
||||||
|
LL | ($($($($i:ident)+)*)?) => {};
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 12 previous errors
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user