rust/tests/ui/macros/macro-at-most-once-rep-2018.rs

43 lines
1.2 KiB
Rust
Raw Normal View History

2019-05-21 22:58:29 -05:00
// Tests that `?` is a Kleene op and not a macro separator in the 2018 edition.
// edition:2018
macro_rules! foo {
2018-11-24 16:27:13 -06:00
($(a)?) => {};
}
// The Kleene op `?` does not admit a separator before it.
macro_rules! baz {
2018-11-24 16:27:13 -06:00
($(a),?) => {}; //~ERROR the `?` macro repetition operator
}
macro_rules! barplus {
2018-11-24 16:27:13 -06:00
($(a)?+) => {}; // ok. matches "a+" and "+"
}
macro_rules! barstar {
2018-11-24 16:27:13 -06:00
($(a)?*) => {}; // ok. matches "a*" and "*"
}
pub fn main() {
foo!();
foo!(a);
foo!(a?); //~ ERROR no rules expected the token `?`
foo!(a?a); //~ ERROR no rules expected the token `?`
foo!(a?a?a); //~ ERROR no rules expected the token `?`
barplus!(); //~ERROR unexpected end of macro invocation
barplus!(a); //~ERROR unexpected end of macro invocation
barplus!(a?); //~ ERROR no rules expected the token `?`
barplus!(a?a); //~ ERROR no rules expected the token `?`
2018-11-24 18:40:03 -06:00
barplus!(a+);
barplus!(+);
barstar!(); //~ERROR unexpected end of macro invocation
barstar!(a); //~ERROR unexpected end of macro invocation
barstar!(a?); //~ ERROR no rules expected the token `?`
barstar!(a?a); //~ ERROR no rules expected the token `?`
barstar!(a*);
barstar!(*);
}