diff options
| author | bors <bors@rust-lang.org> | 2021-02-07 16:48:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-07 16:48:57 +0000 |
| commit | 36ecbc94eb6be90bc38b2d0fdd4bfac3f34d9923 (patch) | |
| tree | d74ad00cf16e17da1e827a9de6757ec9fdc13718 /src/test/ui/pattern | |
| parent | 5a5f3a980c0d2afd55f2162300339471378e341f (diff) | |
| parent | ae6fcab733007b4d59b5b2aac1825bf1f275b0b2 (diff) | |
| download | rust-36ecbc94eb6be90bc38b2d0fdd4bfac3f34d9923.tar.gz rust-36ecbc94eb6be90bc38b2d0fdd4bfac3f34d9923.zip | |
Auto merge of #80632 - Nadrieril:fix-80501, r=varkor
Identify unreachable subpatterns more reliably In https://github.com/rust-lang/rust/pull/80104 I used `Span`s to identify unreachable sub-patterns in the presence of or-patterns during exhaustiveness checking. In https://github.com/rust-lang/rust/issues/80501 it was revealed that `Span`s are complicated and that this was not a good idea. Instead, this PR identifies subpatterns logically: as a path in the tree of subpatterns of a given pattern. I made a struct that captures a set of such subpatterns. This is a bit complex, but thankfully self-contained; the rest of the code does not need to know anything about it. Fixes https://github.com/rust-lang/rust/issues/80501. I think I managed to keep the perf neutral. r? `@varkor`
Diffstat (limited to 'src/test/ui/pattern')
| -rw-r--r-- | src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs new file mode 100644 index 00000000000..aac7d7d5385 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs @@ -0,0 +1,27 @@ +// check-pass +#![deny(unreachable_patterns)] +pub enum TypeCtor { + Slice, + Array, +} + +pub struct ApplicationTy(TypeCtor); + +macro_rules! ty_app { + ($ctor:pat) => { + ApplicationTy($ctor) + }; +} + +fn _foo(ty: ApplicationTy) { + match ty { + ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {} + } + + // same as above, with the macro expanded + match ty { + ApplicationTy(TypeCtor::Array) | ApplicationTy(TypeCtor::Slice) => {} + } +} + +fn main() {} |
