From 3c1a1c622776da5741f178658c611ccf0f75755f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 2 Jan 2021 22:38:18 +0000 Subject: [PATCH] Add tests --- .../exhaustiveness-unreachable-pattern.rs | 16 ++++++++ .../exhaustiveness-unreachable-pattern.stderr | 39 ++++++++++++++----- .../issue-80501-or-pat-and-macro.rs | 27 +++++++++++++ .../issue-80501-or-pat-and-macro.stderr | 18 +++++++++ 4 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs create mode 100644 src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs index 184ffa85c40..f51ba683cab 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs @@ -48,6 +48,22 @@ fn main() { (1 | 1,) => {} //~ ERROR unreachable _ => {} } + match 0 { + (0 | 1) | 1 => {} //~ ERROR unreachable + _ => {} + } + match 0 { + 0 | (0 | 0) => {} + //~^ ERROR unreachable + _ => {} + } + match None { + // There is only one error that correctly points to the whole subpattern + Some(0) | + Some( //~ ERROR unreachable + 0 | 0) => {} + _ => {} + } match [0; 2] { [0 | 0 //~ ERROR unreachable diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index 8b1003b5514..f61e7f2281a 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -77,58 +77,77 @@ LL | (1 | 1,) => {} | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:52:19 + | +LL | (0 | 1) | 1 => {} + | ^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:56:14 + | +LL | 0 | (0 | 0) => {} + | ^^^^^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:63:13 + | +LL | / Some( +LL | | 0 | 0) => {} + | |______________________^ + +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:69:15 | LL | | 0 | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:71:15 | LL | | 0] => {} | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:63:10 + --> $DIR/exhaustiveness-unreachable-pattern.rs:79:10 | LL | [1 | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:75:10 + --> $DIR/exhaustiveness-unreachable-pattern.rs:91:10 | LL | [true | ^^^^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:82:36 + --> $DIR/exhaustiveness-unreachable-pattern.rs:98:36 | LL | (true | false, None | Some(true | ^^^^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:98:14 + --> $DIR/exhaustiveness-unreachable-pattern.rs:114:14 | LL | Some(0 | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:117:19 + --> $DIR/exhaustiveness-unreachable-pattern.rs:133:19 | LL | | false) => {} | ^^^^^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:125:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:141:15 | LL | | true) => {} | ^^^^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:131:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:147:15 | LL | | true, | ^^^^ -error: aborting due to 21 previous errors +error: aborting due to 24 previous errors 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..483edcebd62 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs @@ -0,0 +1,27 @@ +#![deny(unreachable_patterns)] +//~^ NOTE: lint level is defined here +pub enum TypeCtor { + Slice, + Array, +} + +pub struct ApplicationTy(TypeCtor); + +macro_rules! ty_app { + ($ctor:pat) => { + ApplicationTy($ctor) //~ ERROR unreachable pattern + }; +} + +fn _foo(ty: ApplicationTy) { + match ty { + ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {} //~ NOTE: in this expansion + } + + // same as above, with the macro expanded + match ty { + ApplicationTy(TypeCtor::Array) | ApplicationTy(TypeCtor::Slice) => {} + } +} + +fn main() {} diff --git a/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr new file mode 100644 index 00000000000..9d12b4a20e9 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr @@ -0,0 +1,18 @@ +error: unreachable pattern + --> $DIR/issue-80501-or-pat-and-macro.rs:12:9 + | +LL | ApplicationTy($ctor) + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {} + | ------------------------ in this macro invocation + | +note: the lint level is defined here + --> $DIR/issue-80501-or-pat-and-macro.rs:1:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + -- 2.44.0