-
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.
Rollup merge of #84185 - hi-rustin:rustin-patch-macro, r=nikomatsakis
add more pat2021 tests close #84138 r? ```@nikomatsakis```
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs
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,20 @@ | ||
// edition:2021 | ||
#![allow(unused_macros)] | ||
macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments | ||
macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments | ||
macro_rules! qux { ($x:pat, $y:pat) => {} } // should be ok | ||
macro_rules! match_any { | ||
( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments | ||
match $expr { | ||
$( | ||
$( $pat => $expr_arm, )+ | ||
)+ | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
let result: Result<i64, i32> = Err(42); | ||
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into()); | ||
assert_eq!(int, 42); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.stderr
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,26 @@ | ||
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments | ||
--> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:3:28 | ||
| | ||
LL | macro_rules! foo { ($x:pat | $y:pat) => {} } | ||
| ^ not allowed after `pat` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments | ||
--> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:4:32 | ||
| | ||
LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } | ||
| ^ not allowed after `pat` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments | ||
--> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:7:36 | ||
| | ||
LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { | ||
| ^ not allowed after `pat` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: aborting due to 3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// run-pass | ||
#![allow(unused_macros)] | ||
macro_rules! foo { ($x:pat | $y:pat) => {} } // should be ok | ||
macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } // should be ok | ||
macro_rules! qux { ($x:pat, $y:pat) => {} } // should be ok | ||
macro_rules! match_any { | ||
( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { // should be ok | ||
match $expr { | ||
$( | ||
$( $pat => $expr_arm, )+ | ||
)+ | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
let result: Result<i64, i32> = Err(42); | ||
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into()); | ||
assert_eq!(int, 42); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs
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,21 @@ | ||
#![feature(edition_macro_pats)] | ||
#![allow(unused_macros)] | ||
macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments | ||
macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok | ||
macro_rules! qux { ($x:pat2015 | $y:pat2021) => {} } // should be ok | ||
macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments | ||
macro_rules! match_any { | ||
( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments | ||
match $expr { | ||
$( | ||
$( $pat => $expr_arm, )+ | ||
)+ | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
let result: Result<i64, i32> = Err(42); | ||
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into()); | ||
assert_eq!(int, 42); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr
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,26 @@ | ||
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments | ||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32 | ||
| | ||
LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } | ||
| ^ not allowed after `pat2021` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments | ||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32 | ||
| | ||
LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } | ||
| ^ not allowed after `pat2021` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments | ||
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40 | ||
| | ||
LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { | ||
| ^ not allowed after `pat2021` fragments | ||
| | ||
= note: allowed there are: `=>`, `,`, `=`, `if` or `in` | ||
|
||
error: aborting due to 3 previous errors | ||
|