Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jan 24, 2021
1 parent 7d38181 commit 3c1a1c6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs
Expand Up @@ -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
Expand Down
39 changes: 29 additions & 10 deletions src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr
Expand Up @@ -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

27 changes: 27 additions & 0 deletions 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() {}
18 changes: 18 additions & 0 deletions 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

0 comments on commit 3c1a1c6

Please sign in to comment.