-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests since ? macro op is supported on 2015.
- Loading branch information
Showing
12 changed files
with
185 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// run-pass | ||
#![allow(unused_mut)] | ||
// The logic for parsing Kleene operators in macros has a special case to disambiguate `?`. | ||
// Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the | ||
// ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to | ||
// exercise that logic in the macro parser. | ||
// | ||
// Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but | ||
// included for consistency with `+` and `*`. | ||
// | ||
// This test focuses on non-error cases and making sure the correct number of repetitions happen. | ||
|
||
// edition:2015 | ||
|
||
macro_rules! foo { | ||
($($a:ident)? ; $num:expr) => { { | ||
let mut x = 0; | ||
|
||
$( | ||
x += $a; | ||
)? | ||
|
||
assert_eq!(x, $num); | ||
} } | ||
} | ||
|
||
pub fn main() { | ||
let a = 1; | ||
|
||
// accept 0 or 1 repetitions | ||
foo!( ; 0); | ||
foo!(a ; 1); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.stderr
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.stderr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Tests that `?` is a Kleene op and not a macro separator in the 2015 edition. | ||
|
||
// edition:2015 | ||
|
||
macro_rules! foo { | ||
($(a)?) => {}; | ||
} | ||
|
||
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 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 `?` | ||
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!(*); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
error: the `?` macro repetition operator does not take a separator | ||
--> $DIR/macro-at-most-once-rep-2015.rs:10:10 | ||
| | ||
LL | ($(a),?) => {}; | ||
| ^ | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:24:11 | ||
| | ||
LL | macro_rules! foo { | ||
| ---------------- when calling this macro | ||
... | ||
LL | foo!(a?); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:25:11 | ||
| | ||
LL | macro_rules! foo { | ||
| ---------------- when calling this macro | ||
... | ||
LL | foo!(a?a); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:26:11 | ||
| | ||
LL | macro_rules! foo { | ||
| ---------------- when calling this macro | ||
... | ||
LL | foo!(a?a?a); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/macro-at-most-once-rep-2015.rs:28:5 | ||
| | ||
LL | macro_rules! barplus { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barplus!(); | ||
| ^^^^^^^^^^^ missing tokens in macro arguments | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/macro-at-most-once-rep-2015.rs:29:15 | ||
| | ||
LL | macro_rules! barplus { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barplus!(a); | ||
| ^ missing tokens in macro arguments | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:30:15 | ||
| | ||
LL | macro_rules! barplus { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barplus!(a?); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:31:15 | ||
| | ||
LL | macro_rules! barplus { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barplus!(a?a); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/macro-at-most-once-rep-2015.rs:35:5 | ||
| | ||
LL | macro_rules! barstar { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barstar!(); | ||
| ^^^^^^^^^^^ missing tokens in macro arguments | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/macro-at-most-once-rep-2015.rs:36:15 | ||
| | ||
LL | macro_rules! barstar { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barstar!(a); | ||
| ^ missing tokens in macro arguments | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:37:15 | ||
| | ||
LL | macro_rules! barstar { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barstar!(a?); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: no rules expected the token `?` | ||
--> $DIR/macro-at-most-once-rep-2015.rs:38:15 | ||
| | ||
LL | macro_rules! barstar { | ||
| -------------------- when calling this macro | ||
... | ||
LL | barstar!(a?a); | ||
| ^ no rules expected this token in macro call | ||
|
||
error: aborting due to 12 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters