diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 8380116010b49..87fdbf2dca392 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -140,7 +140,7 @@ macro_rules! assert_ne { #[allow_internal_unstable(core_panic)] #[rustc_macro_transparency = "semitransparent"] pub macro assert_matches { - ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({ + ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} ref left_val => { @@ -152,7 +152,7 @@ pub macro assert_matches { } } }), - ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ + ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} ref left_val => { @@ -320,7 +320,7 @@ pub macro debug_assert_matches($($arg:tt)*) { #[macro_export] #[stable(feature = "matches_macro", since = "1.42.0")] macro_rules! matches { - ($expression:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => { + ($expression:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => { match $expression { $( $pattern )|+ $( if $guard )? => true, _ => false diff --git a/library/core/tests/macros.rs b/library/core/tests/macros.rs index 482f3c1c99840..ff3632e3550c2 100644 --- a/library/core/tests/macros.rs +++ b/library/core/tests/macros.rs @@ -12,3 +12,9 @@ fn assert_escape() { fn assert_ne_trailing_comma() { assert_ne!(1, 2,); } + +#[rustfmt::skip] +#[test] +fn matches_leading_pipe() { + matches!(1, | 1 | 2 | 3); +}