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 02:53:58 -05:00
#![allow(unused_macros)]
2019-01-15 11:31:49 -06:00
// Tests that repetition matchers cannot match the empty token tree (since that would be
// ambiguous).
// edition:2018
2016-09-25 11:55:04 -05:00
macro_rules! foo {
( $()* ) => {};
//~^ ERROR repetition matches empty token tree
( $()+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 11:31:49 -06:00
( $()? ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 11:55:04 -05:00
( $(),* ) => {}; // PASS
( $(),+ ) => {}; // PASS
2019-01-15 11:31:49 -06:00
// `?` cannot have a separator...
2016-09-25 11:55:04 -05:00
( [$()*] ) => {};
//~^ ERROR repetition matches empty token tree
( [$()+] ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 11:31:49 -06:00
( [$()?] ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 11:55:04 -05:00
( [$(),*] ) => {}; // PASS
( [$(),+] ) => {}; // PASS
2019-01-15 11:31:49 -06:00
// `?` cannot have a separator...
2016-09-25 11:55:04 -05:00
( $($()* $(),* $(a)* $(a),* )* ) => {};
//~^ ERROR repetition matches empty token tree
( $($()* $(),* $(a)* $(a),* )+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 11:31:49 -06: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 11:55:04 -05:00
( $(a $(),* $(a)* $(a),* )* ) => {}; // PASS
( $($(a)+ $(),* $(a)* $(a),* )+ ) => {}; // PASS
2019-01-15 11:31:49 -06:00
( $($(a)+ $(),* $(a)* $(a),* )? ) => {}; // PASS
( $(a $(),* $(a)? $(a),* )* ) => {}; // PASS
( $($(a)+ $(),* $(a)? $(a),* )+ ) => {}; // PASS
( $($(a)+ $(),* $(a)? $(a),* )? ) => {}; // PASS
2016-09-25 11:55:04 -05:00
( $(a $()+)* ) => {};
//~^ ERROR repetition matches empty token tree
( $(a $()*)+ ) => {};
//~^ ERROR repetition matches empty token tree
2019-01-15 11:31:49 -06:00
( $(a $()+)? ) => {};
//~^ ERROR repetition matches empty token tree
( $(a $()?)+ ) => {};
//~^ ERROR repetition matches empty token tree
2016-09-25 11:55:04 -05:00
}
// Original Issue
2016-09-25 11:55:04 -05: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 11:55:04 -05:00
}
// Minified Issue
2016-09-25 11:55:04 -05:00
macro_rules! m {
2019-01-15 11:31:49 -06:00
( $()* ) => {};
2016-09-25 11:55:04 -05:00
//~^ ERROR repetition matches empty token tree
}
m!();