-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #60932 - Centril:macro-at-most-once-2015, r=<try>
Support ? Kleene macro operator in 2015 Closes #56668. See that issue for rationale and discussion. Crater will be needed and then, if all goes well, FCP.
- Loading branch information
Showing
13 changed files
with
189 additions
and
254 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
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!(*); | ||
} |
Oops, something went wrong.