Skip to content

Commit 3c2a709

Browse files
authored
Rollup merge of #85678 - lukas-code:matches2021, r=dtolnay
fix `matches!` and `assert_matches!` on edition 2021 Previously this code failed to compile on edition 2021. [(Playground)](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=53960f2f051f641777b9e458da747707) ```rust fn main() { matches!((), ()); } ``` ``` Compiling playground v0.0.1 (/playground) error: `$pattern:pat` may be followed by `|`, which is not allowed for `pat` fragments | = note: allowed there are: `=>`, `,`, `=`, `if` or `in` error: aborting due to previous error error: could not compile `playground` To learn more, run the command again with --verbose. ```
2 parents 12ab323 + 824c743 commit 3c2a709

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#![feature(no_coverage)] // rust-lang/rust#84605
169169
#![feature(int_error_matching)]
170170
#![deny(unsafe_op_in_unsafe_fn)]
171+
#![deny(or_patterns_back_compat)]
171172

172173
// allow using `core::` in intra-doc links
173174
#[allow(unused_extern_crates)]

library/core/src/macros/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ macro_rules! assert_ne {
138138
#[unstable(feature = "assert_matches", issue = "82775")]
139139
#[allow_internal_unstable(core_panic)]
140140
macro_rules! assert_matches {
141-
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => ({
141+
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
142142
match $left {
143143
$( $pattern )|+ $( if $guard )? => {}
144144
ref left_val => {
@@ -150,7 +150,7 @@ macro_rules! assert_matches {
150150
}
151151
}
152152
});
153-
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
153+
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
154154
match $left {
155155
$( $pattern )|+ $( if $guard )? => {}
156156
ref left_val => {
@@ -315,7 +315,7 @@ macro_rules! debug_assert_matches {
315315
#[macro_export]
316316
#[stable(feature = "matches_macro", since = "1.42.0")]
317317
macro_rules! matches {
318-
($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => {
318+
($expression:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
319319
match $expression {
320320
$( $pattern )|+ $( if $guard )? => true,
321321
_ => false

src/test/ui/matches2021.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-pass
2+
// edition:2021
3+
// compile-flags: -Zunstable-options
4+
5+
// regression test for https://github.com/rust-lang/rust/pull/85678
6+
7+
#![feature(assert_matches)]
8+
9+
fn main() {
10+
assert!(matches!((), ()));
11+
assert_matches!((), ());
12+
}

0 commit comments

Comments
 (0)