diff options
| author | bors <bors@rust-lang.org> | 2020-12-20 04:10:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-12-20 04:10:44 +0000 |
| commit | 29e32120c33d30ff526fc7f4d94ec9fce0dc10c9 (patch) | |
| tree | 398584715bf13334395d2228f5cf6e7e09a3d792 /src/test/ui/pattern | |
| parent | 0c11b93f5a8914a40f619b0a1663baafe029d427 (diff) | |
| parent | 1a7d00a529503ac38a6b1ae28e8e779e434e02e0 (diff) | |
| download | rust-29e32120c33d30ff526fc7f4d94ec9fce0dc10c9.tar.gz rust-29e32120c33d30ff526fc7f4d94ec9fce0dc10c9.zip | |
Auto merge of #80100 - mark-i-m:pattORns-2, r=petrochenkov
or_patterns: implement :pat edition-specific behavior cc #54883 `@joshtriplett` This PR implements the edition-specific behavior of `:pat` wrt or-patterns, as determined by the crater runs and T-lang consensus in https://github.com/rust-lang/rust/issues/54883#issuecomment-745509090. I believe this can unblock stabilization of or_patterns. r? `@petrochenkov`
Diffstat (limited to 'src/test/ui/pattern')
| -rw-r--r-- | src/test/ui/pattern/or-pattern-macro-pat.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/ui/pattern/or-pattern-macro-pat.rs b/src/test/ui/pattern/or-pattern-macro-pat.rs new file mode 100644 index 00000000000..8749407675b --- /dev/null +++ b/src/test/ui/pattern/or-pattern-macro-pat.rs @@ -0,0 +1,44 @@ +// run-pass +// edition:2021 +// ignore-test +// FIXME(mark-i-m): enable this test again when 2021 machinery is available + +#![feature(or_patterns)] + +use Foo::*; + +#[derive(Eq, PartialEq, Debug)] +enum Foo { + A(u64), + B(u64), + C, + D, +} + +macro_rules! foo { + ($orpat:pat, $val:expr) => { + match $val { + x @ ($orpat) => x, // leading vert would not be allowed in $orpat + _ => B(0xDEADBEEFu64), + } + }; +} + +macro_rules! bar { + ($orpat:pat, $val:expr) => { + match $val { + $orpat => 42, // leading vert allowed here + _ => 0xDEADBEEFu64, + } + }; +} + +fn main() { + // Test or-pattern. + let y = foo!(A(_)|B(_), A(32)); + assert_eq!(y, A(32)); + + // Leading vert in or-pattern. + let y = bar!(|C| D, C); + assert_eq!(y, 42u64); +} |
