]> git.lizzy.rs Git - rust.git/blob - src/test/ui/macros/macro-at-most-once-rep-2018.rs
Rollup merge of #53407 - pnkfelix:partial-53351-make-more-ported-compile-fail-tests...
[rust.git] / src / test / ui / macros / macro-at-most-once-rep-2018.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Tests that `?` is a Kleene op and not a macro separator in the 2018 edition.
12
13 // compile-flags: --edition=2018
14
15 #![feature(macro_at_most_once_rep)]
16
17 macro_rules! foo {
18     ($(a)?) => {}
19 }
20
21 macro_rules! baz {
22     ($(a),?) => {} //~ERROR the `?` macro repetition operator
23 }
24
25 macro_rules! barplus {
26     ($(a)?+) => {} // ok. matches "a+" and "+"
27 }
28
29 macro_rules! barstar {
30     ($(a)?*) => {} // ok. matches "a*" and "*"
31 }
32
33 pub fn main() {
34     foo!();
35     foo!(a);
36     foo!(a?); //~ ERROR no rules expected the token `?`
37     foo!(a?a); //~ ERROR no rules expected the token `?`
38     foo!(a?a?a); //~ ERROR no rules expected the token `?`
39
40     barplus!(); //~ERROR unexpected end of macro invocation
41     barplus!(a); //~ERROR unexpected end of macro invocation
42     barplus!(a?); //~ ERROR no rules expected the token `?`
43     barplus!(a?a); //~ ERROR no rules expected the token `?`
44     barplus!(a+);
45     barplus!(+);
46
47     barstar!(); //~ERROR unexpected end of macro invocation
48     barstar!(a); //~ERROR unexpected end of macro invocation
49     barstar!(a?); //~ ERROR no rules expected the token `?`
50     barstar!(a?a); //~ ERROR no rules expected the token `?`
51     barstar!(a*);
52     barstar!(*);
53 }