diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2021-05-14 00:44:58 +0300 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2021-07-15 22:05:45 +0300 |
| commit | f10da9f50ac7d083b2f5b2bc8b84c777ed411973 (patch) | |
| tree | 7eb87a98558a42bc7d016e3e49369053eb090c34 | |
| parent | 0a6c636c40540707cdfd542866998862e8aa72e8 (diff) | |
| download | rust-f10da9f50ac7d083b2f5b2bc8b84c777ed411973.tar.gz rust-f10da9f50ac7d083b2f5b2bc8b84c777ed411973.zip | |
Allow leading pipe in `matches!()` patterns.
This is allowed in `match` statement, and stated in https://internals.rust-lang.org/t/leading-pipe-in-core-matches/14699/2 that it should be allowed in these macros too.
| -rw-r--r-- | library/core/src/macros/mod.rs | 6 | ||||
| -rw-r--r-- | library/core/tests/macros.rs | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 8ce441e80bf..d26699e26e3 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -141,7 +141,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 => { @@ -153,7 +153,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 => { @@ -321,7 +321,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 482f3c1c998..ff3632e3550 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); +} |
