Add tests
This commit is contained in:
parent
2225ee1b62
commit
2309783a0b
7 changed files with 95 additions and 19 deletions
|
@ -64,6 +64,37 @@ fn main() {
|
||||||
| 2, ..] => {}
|
| 2, ..] => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
// FIXME: incorrect
|
||||||
|
match &[][..] {
|
||||||
|
[true] => {}
|
||||||
|
[true //~ ERROR unreachable
|
||||||
|
| false, ..] => {}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
match &[][..] {
|
||||||
|
[false] => {}
|
||||||
|
[true, ..] => {}
|
||||||
|
[true //~ ERROR unreachable
|
||||||
|
| false, ..] => {}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
match (true, None) {
|
||||||
|
(true, Some(_)) => {}
|
||||||
|
(false, Some(true)) => {}
|
||||||
|
(true | false, None | Some(true // FIXME: should be unreachable
|
||||||
|
| false)) => {}
|
||||||
|
}
|
||||||
|
macro_rules! t_or_f {
|
||||||
|
() => {
|
||||||
|
(true // FIXME: should be unreachable
|
||||||
|
| false)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
match (true, None) {
|
||||||
|
(true, Some(_)) => {}
|
||||||
|
(false, Some(true)) => {}
|
||||||
|
(true | false, None | Some(t_or_f!())) => {}
|
||||||
|
}
|
||||||
match Some(0) {
|
match Some(0) {
|
||||||
Some(0) => {}
|
Some(0) => {}
|
||||||
Some(0 //~ ERROR unreachable
|
Some(0 //~ ERROR unreachable
|
||||||
|
|
|
@ -95,28 +95,40 @@ LL | [1
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: unreachable pattern
|
error: unreachable pattern
|
||||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:69:14
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:70:10
|
||||||
|
|
|
||||||
|
LL | [true
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
error: unreachable pattern
|
||||||
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:77:10
|
||||||
|
|
|
||||||
|
LL | [true
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
error: unreachable pattern
|
||||||
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:100:14
|
||||||
|
|
|
|
||||||
LL | Some(0
|
LL | Some(0
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: unreachable pattern
|
error: unreachable pattern
|
||||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:88:19
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:119:19
|
||||||
|
|
|
|
||||||
LL | | false) => {}
|
LL | | false) => {}
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: unreachable pattern
|
error: unreachable pattern
|
||||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:96:15
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:127:15
|
||||||
|
|
|
|
||||||
LL | | true) => {}
|
LL | | true) => {}
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: unreachable pattern
|
error: unreachable pattern
|
||||||
--> $DIR/exhaustiveness-unreachable-pattern.rs:102:15
|
--> $DIR/exhaustiveness-unreachable-pattern.rs:133:15
|
||||||
|
|
|
|
||||||
LL | | true,
|
LL | | true,
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 19 previous errors
|
error: aborting due to 21 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
pub enum T {
|
pub enum T {
|
||||||
T1(()),
|
T1(()),
|
||||||
T2(())
|
T2(()),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum V {
|
pub enum V {
|
||||||
V1(isize),
|
V1(isize),
|
||||||
V2(bool)
|
V2(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match (T::T1(()), V::V2(true)) {
|
match (T::T1(()), V::V2(true)) {
|
||||||
//~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
|
//~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
|
||||||
(T::T1(()), V::V1(i)) => (),
|
(T::T1(()), V::V1(i)) => (),
|
||||||
(T::T2(()), V::V2(b)) => ()
|
(T::T2(()), V::V2(b)) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ fn foo(a: Option<usize>, b: Option<usize>) {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
//~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
|
//~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
|
||||||
(Some(a), Some(b)) if a == b => {}
|
(Some(a), Some(b)) if a == b => {}
|
||||||
(Some(_), None) |
|
(Some(_), None) | (None, Some(_)) => {}
|
||||||
(None, Some(_)) => { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0004]: non-exhaustive patterns: `(None, None)` not covered
|
error[E0004]: non-exhaustive patterns: `(None, None)` not covered
|
||||||
--> $DIR/issue-2111.rs:2:9
|
--> $DIR/issue-2111.rs:2:11
|
||||||
|
|
|
|
||||||
LL | match (a, b) {
|
LL | match (a, b) {
|
||||||
| ^^^^^ pattern `(None, None)` not covered
|
| ^^^^^^ pattern `(None, None)` not covered
|
||||||
|
|
|
|
||||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||||
= note: the matched value is of type `(Option<usize>, Option<usize>)`
|
= note: the matched value is of type `(Option<usize>, Option<usize>)`
|
||||||
|
|
14
src/test/ui/pattern/usefulness/issue-56379.rs
Normal file
14
src/test/ui/pattern/usefulness/issue-56379.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
enum Foo {
|
||||||
|
A(bool),
|
||||||
|
B(bool),
|
||||||
|
C(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match Foo::A(true) {
|
||||||
|
//~^ ERROR non-exhaustive patterns: `A(false)` not covered
|
||||||
|
Foo::A(true) => {}
|
||||||
|
Foo::B(true) => {}
|
||||||
|
Foo::C(true) => {}
|
||||||
|
}
|
||||||
|
}
|
20
src/test/ui/pattern/usefulness/issue-56379.stderr
Normal file
20
src/test/ui/pattern/usefulness/issue-56379.stderr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
error[E0004]: non-exhaustive patterns: `A(false)` not covered
|
||||||
|
--> $DIR/issue-56379.rs:8:11
|
||||||
|
|
|
||||||
|
LL | / enum Foo {
|
||||||
|
LL | | A(bool),
|
||||||
|
| | - not covered
|
||||||
|
LL | | B(bool),
|
||||||
|
LL | | C(bool),
|
||||||
|
LL | | }
|
||||||
|
| |_- `Foo` defined here
|
||||||
|
...
|
||||||
|
LL | match Foo::A(true) {
|
||||||
|
| ^^^^^^^^^^^^ pattern `A(false)` not covered
|
||||||
|
|
|
||||||
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||||
|
= note: the matched value is of type `Foo`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0004`.
|
Loading…
Add table
Add a link
Reference in a new issue