diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2019-11-30 15:51:26 +0000 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2019-12-04 16:43:21 +0000 |
| commit | 922310d60fcd2c84c2f2b10ca465538cb160d25d (patch) | |
| tree | d93f0e14d01b04f924d7dd6ea95c39d0e7f6bd8e /src/test/ui/pattern | |
| parent | 063d74f5d9b4a08b103137405baa076c55df9eae (diff) | |
| download | rust-922310d60fcd2c84c2f2b10ca465538cb160d25d.tar.gz rust-922310d60fcd2c84c2f2b10ca465538cb160d25d.zip | |
Add tests
Diffstat (limited to 'src/test/ui/pattern')
4 files changed, 229 insertions, 0 deletions
diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs new file mode 100644 index 00000000000..0a8194253a3 --- /dev/null +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.rs @@ -0,0 +1,46 @@ +#![feature(never_type)] +#![feature(exhaustive_patterns)] +#![deny(unreachable_patterns)] +enum Foo {} + +struct NonEmptyStruct(bool); +enum NonEmptyEnum1 { + Foo(bool), +} +enum NonEmptyEnum2 { + Foo(bool), + Bar, +} +enum NonEmptyEnum5 { + V1, V2, V3, V4, V5, +} + +fn foo(x: Foo) { + match x {} // ok + match x { + _ => {}, //~ ERROR unreachable pattern + } +} + +fn main() { + // `exhaustive_patterns` is not on, so uninhabited branches are not detected as unreachable. + match None::<!> { + None => {} + Some(_) => {} //~ ERROR unreachable pattern + } + match None::<Foo> { + None => {} + Some(_) => {} //~ ERROR unreachable pattern + } + + match 0u8 {} + //~^ ERROR type `u8` is non-empty + match NonEmptyStruct(true) {} + //~^ ERROR type `NonEmptyStruct` is non-empty + match NonEmptyEnum1::Foo(true) {} + //~^ ERROR type `NonEmptyEnum1` is non-empty + match NonEmptyEnum2::Foo(true) {} + //~^ ERROR type `NonEmptyEnum2` is non-empty + match NonEmptyEnum5::V1 {} + //~^ ERROR type `NonEmptyEnum5` is non-empty +} diff --git a/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr new file mode 100644 index 00000000000..8d143494026 --- /dev/null +++ b/src/test/ui/pattern/usefulness/match-empty-exhaustive_patterns.stderr @@ -0,0 +1,67 @@ +error: unreachable pattern + --> $DIR/match-empty-exhaustive_patterns.rs:21:9 + | +LL | _ => {}, + | ^ + | +note: lint level defined here + --> $DIR/match-empty-exhaustive_patterns.rs:3:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/match-empty-exhaustive_patterns.rs:29:9 + | +LL | Some(_) => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/match-empty-exhaustive_patterns.rs:33:9 + | +LL | Some(_) => {} + | ^^^^^^^ + +error[E0004]: non-exhaustive patterns: type `u8` is non-empty + --> $DIR/match-empty-exhaustive_patterns.rs:36:11 + | +LL | match 0u8 {} + | ^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty + --> $DIR/match-empty-exhaustive_patterns.rs:38:11 + | +LL | match NonEmptyStruct(true) {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: type `NonEmptyEnum1` is non-empty + --> $DIR/match-empty-exhaustive_patterns.rs:40:11 + | +LL | match NonEmptyEnum1::Foo(true) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: type `NonEmptyEnum2` is non-empty + --> $DIR/match-empty-exhaustive_patterns.rs:42:11 + | +LL | match NonEmptyEnum2::Foo(true) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: type `NonEmptyEnum5` is non-empty + --> $DIR/match-empty-exhaustive_patterns.rs:44:11 + | +LL | match NonEmptyEnum5::V1 {} + | ^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/pattern/usefulness/match-empty.rs b/src/test/ui/pattern/usefulness/match-empty.rs new file mode 100644 index 00000000000..28ebde6c4c1 --- /dev/null +++ b/src/test/ui/pattern/usefulness/match-empty.rs @@ -0,0 +1,48 @@ +#![feature(never_type)] +#![deny(unreachable_patterns)] +enum Foo {} + +struct NonEmptyStruct(bool); //~ `NonEmptyStruct` defined here +enum NonEmptyEnum1 { //~ `NonEmptyEnum1` defined here + Foo(bool), //~ variant not covered +} +enum NonEmptyEnum2 { //~ `NonEmptyEnum2` defined here + Foo(bool), //~ variant not covered + Bar, //~ variant not covered +} +enum NonEmptyEnum5 { //~ `NonEmptyEnum5` defined here + V1, V2, V3, V4, V5, +} + +fn foo1(x: Foo) { + match x {} // ok +} + +fn foo2(x: Foo) { + match x { + _ => {}, // FIXME: should be unreachable + } +} + +fn main() { + // `exhaustive_patterns` is not on, so uninhabited branches are not detected as unreachable. + match None::<!> { + None => {} + Some(_) => {} + } + match None::<Foo> { + None => {} + Some(_) => {} + } + + match 0u8 {} + //~^ ERROR type `u8` is non-empty + match NonEmptyStruct(true) {} + //~^ ERROR pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + match NonEmptyEnum1::Foo(true) {} + //~^ ERROR pattern `Foo` of type `NonEmptyEnum1` is not handled + match NonEmptyEnum2::Foo(true) {} + //~^ ERROR multiple patterns of type `NonEmptyEnum2` are not handled + match NonEmptyEnum5::V1 {} + //~^ ERROR type `NonEmptyEnum5` is non-empty +} diff --git a/src/test/ui/pattern/usefulness/match-empty.stderr b/src/test/ui/pattern/usefulness/match-empty.stderr new file mode 100644 index 00000000000..eb6cfaa61df --- /dev/null +++ b/src/test/ui/pattern/usefulness/match-empty.stderr @@ -0,0 +1,68 @@ +error[E0004]: non-exhaustive patterns: type `u8` is non-empty + --> $DIR/match-empty.rs:38:11 + | +LL | match 0u8 {} + | ^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: pattern `NonEmptyStruct` of type `NonEmptyStruct` is not handled + --> $DIR/match-empty.rs:40:11 + | +LL | struct NonEmptyStruct(bool); + | ---------------------------- + | | | + | | variant not covered + | `NonEmptyStruct` defined here +... +LL | match NonEmptyStruct(true) {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: pattern `Foo` of type `NonEmptyEnum1` is not handled + --> $DIR/match-empty.rs:42:11 + | +LL | / enum NonEmptyEnum1 { +LL | | Foo(bool), + | | --- variant not covered +LL | | } + | |_- `NonEmptyEnum1` defined here +... +LL | match NonEmptyEnum1::Foo(true) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: multiple patterns of type `NonEmptyEnum2` are not handled + --> $DIR/match-empty.rs:44:11 + | +LL | / enum NonEmptyEnum2 { +LL | | Foo(bool), + | | --- variant not covered +LL | | Bar, + | | --- variant not covered +LL | | } + | |_- `NonEmptyEnum2` defined here +... +LL | match NonEmptyEnum2::Foo(true) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: type `NonEmptyEnum5` is non-empty + --> $DIR/match-empty.rs:46:11 + | +LL | / enum NonEmptyEnum5 { +LL | | V1, V2, V3, V4, V5, +LL | | } + | |_- `NonEmptyEnum5` defined here +... +LL | match NonEmptyEnum5::V1 {} + | ^^^^^^^^^^^^^^^^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0004`. |
