rust/tests/ui/issues/issue-5067.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.3 KiB
Rust
Raw Normal View History

2017-05-12 07:53:58 +00:00
#![allow(unused_macros)]
2019-01-15 17:31:49 +00:00
// Tests that repetition matchers cannot match the empty token tree (since that would be
// ambiguous).
// edition:2018
2016-09-25 16:55:04 +00:00
macro_rules! foo {
( $()* ) => {};
//~^ ERROR repetition matches empty token tree
( $()+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 17:31:49 +00:00
( $()? ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 16:55:04 +00:00
( $(),* ) => {}; // PASS
( $(),+ ) => {}; // PASS
2019-01-15 17:31:49 +00:00
// `?` cannot have a separator...
2016-09-25 16:55:04 +00:00
( [$()*] ) => {};
//~^ ERROR repetition matches empty token tree
( [$()+] ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 17:31:49 +00:00
( [$()?] ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 16:55:04 +00:00
( [$(),*] ) => {}; // PASS
( [$(),+] ) => {}; // PASS
2019-01-15 17:31:49 +00:00
// `?` cannot have a separator...
2016-09-25 16:55:04 +00:00
( $($()* $(),* $(a)* $(a),* )* ) => {};
//~^ ERROR repetition matches empty token tree
( $($()* $(),* $(a)* $(a),* )+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 17:31:49 +00:00
( $($()* $(),* $(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
2016-09-25 16:55:04 +00:00
( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
2019-01-15 17:31:49 +00:00
( $($(a)+ $(),* $(a)* $(a),* )? ) => {}; // PASS
( $(a $(),* $(a)? $(a),* )* ) => {}; // PASS
( $($(a)+ $(),* $(a)? $(a),* )+ ) => {}; // PASS
( $($(a)+ $(),* $(a)? $(a),* )? ) => {}; // PASS
2016-09-25 16:55:04 +00:00
( $(a $()+)* ) => {};
//~^ ERROR repetition matches empty token tree
( $(a $()*)+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 17:31:49 +00:00
( $(a $()+)? ) => {};
//~^ ERROR repetition matches empty token tree
( $(a $()?)+ ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 16:55:04 +00:00
}
// Original Issue
2016-09-25 16:55:04 +00:00
macro_rules! make_vec {
(a $e1:expr $($(, a $e2:expr)*)*) => ([$e1 $($(, $e2)*)*]);
//~^ ERROR repetition matches empty token tree
}
fn main() {
let _ = make_vec![a 1, a 2, a 3];
2016-09-25 16:55:04 +00:00
}
// Minified Issue
2016-09-25 16:55:04 +00:00
macro_rules! m {
2019-01-15 17:31:49 +00:00
( $()* ) => {};
2016-09-25 16:55:04 +00:00
//~^ ERROR repetition matches empty token tree
}
m!();