rust/tests/ui/macros/macro-at-most-once-rep-2018.rs
Nicholas Nethercote dd2b027d5d Tweak more warnings.
Much like the previous commit.

I think the removal of "the token" in each message is fine here. There
are many more error messages that mention tokens without saying "the
token" than those that do say it.
2024-10-28 14:20:28 +11:00

43 lines
1.1 KiB
Rust

// Tests that `?` is a Kleene op and not a macro separator in the 2018 edition.
//@ edition:2018
macro_rules! foo {
($(a)?) => {};
}
// The Kleene op `?` does not admit a separator before it.
macro_rules! baz {
($(a),?) => {}; //~ERROR the `?` macro repetition operator
}
macro_rules! barplus {
($(a)?+) => {}; // ok. matches "a+" and "+"
}
macro_rules! barstar {
($(a)?*) => {}; // ok. matches "a*" and "*"
}
pub fn main() {
foo!();
foo!(a);
foo!(a?); //~ ERROR no rules expected `?`
foo!(a?a); //~ ERROR no rules expected `?`
foo!(a?a?a); //~ ERROR no rules expected `?`
barplus!(); //~ERROR unexpected end of macro invocation
barplus!(a); //~ERROR unexpected end of macro invocation
barplus!(a?); //~ ERROR no rules expected `?`
barplus!(a?a); //~ ERROR no rules expected `?`
barplus!(a+);
barplus!(+);
barstar!(); //~ERROR unexpected end of macro invocation
barstar!(a); //~ERROR unexpected end of macro invocation
barstar!(a?); //~ ERROR no rules expected `?`
barstar!(a?a); //~ ERROR no rules expected `?`
barstar!(a*);
barstar!(*);
}