Auto merge of #79243 - Nadrieril:consolidate-tests, r=varkor
Consolidate exhaustiveness-related tests I hunted for tests that only exercised the match exhaustiveness algorithm and regrouped them. I also improved integer-range tests since I had found them lacking while hacking around. The interest is mainly so that one can pass `--test-args patterns` and catch most relevant tests. r? `@varkor` `@rustbot` modify labels: +A-exhaustiveness-checking
This commit is contained in:
commit
c643dd2ec8
71 changed files with 908 additions and 665 deletions
|
|
@ -1,21 +0,0 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
enum IntList {
|
||||
Cons(isize, Box<IntList>),
|
||||
Nil
|
||||
}
|
||||
|
||||
fn tail(source_list: &IntList) -> IntList {
|
||||
match source_list {
|
||||
&IntList::Cons(val, box ref next_list) => tail(next_list),
|
||||
&IntList::Cons(val, box IntList::Nil) => IntList::Cons(val, box IntList::Nil),
|
||||
//~^ ERROR unreachable pattern
|
||||
_ => panic!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-12116.rs:15:9
|
||||
|
|
||||
LL | &IntList::Cons(val, box IntList::Nil) => IntList::Cons(val, box IntList::Nil),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-12116.rs:5:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
let sl = vec![1,2,3];
|
||||
let v: isize = match &*sl {
|
||||
&[] => 0,
|
||||
&[a,b,c] => 3,
|
||||
&[a, ref rest @ ..] => a,
|
||||
&[10,a, ref rest @ ..] => 10 //~ ERROR: unreachable pattern
|
||||
};
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-12369.rs:9:9
|
||||
|
|
||||
LL | &[10,a, ref rest @ ..] => 10
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-12369.rs:1:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#![allow(overflowing_literals)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn test(val: u8) {
|
||||
match val {
|
||||
256 => print!("0b1110\n"),
|
||||
512 => print!("0b1111\n"),
|
||||
//~^ ERROR: unreachable pattern
|
||||
_ => print!("fail\n"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(1);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-13727.rs:7:5
|
||||
|
|
||||
LL | 512 => print!("0b1111\n"),
|
||||
| ^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-13727.rs:2:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
pub enum T {
|
||||
T1(()),
|
||||
T2(())
|
||||
}
|
||||
|
||||
pub enum V {
|
||||
V1(isize),
|
||||
V2(bool)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match (T::T1(()), V::V2(true)) {
|
||||
//~^ ERROR non-exhaustive patterns: `(T1(()), V2(_))` not covered
|
||||
(T::T1(()), V::V1(i)) => (),
|
||||
(T::T2(()), V::V2(b)) => ()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `(T1(()), V2(_))` not covered
|
||||
--> $DIR/issue-15129.rs:12:11
|
||||
|
|
||||
LL | match (T::T1(()), V::V2(true)) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `(T1(()), V2(_))` 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 `(T, V)`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
fn foo(a: Option<usize>, b: Option<usize>) {
|
||||
match (a,b) {
|
||||
//~^ ERROR: non-exhaustive patterns: `(None, None)` not covered
|
||||
(Some(a), Some(b)) if a == b => { }
|
||||
(Some(_), None) |
|
||||
(None, Some(_)) => { }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(None, None);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `(None, None)` not covered
|
||||
--> $DIR/issue-2111.rs:2:9
|
||||
|
|
||||
LL | match (a,b) {
|
||||
| ^^^^^ pattern `(None, None)` 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 `(Option<usize>, Option<usize>)`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
match "world" {
|
||||
"hello" => {}
|
||||
_ => {},
|
||||
}
|
||||
|
||||
match "world" {
|
||||
ref _x if false => {}
|
||||
"hello" => {}
|
||||
"hello" => {} //~ ERROR unreachable pattern
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-30240-b.rs:12:9
|
||||
|
|
||||
LL | "hello" => {}
|
||||
| ^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-30240-b.rs:1:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
// run-pass
|
||||
fn main() {
|
||||
let &ref a = &[0i32] as &[_];
|
||||
assert_eq!(a, &[0i32] as &[_]);
|
||||
|
||||
let &ref a = "hello";
|
||||
assert_eq!(a, "hello");
|
||||
|
||||
match "foo" {
|
||||
"fool" => unreachable!(),
|
||||
"foo" => {},
|
||||
ref _x => unreachable!()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
fn main() {
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `&_`
|
||||
"hello" => {}
|
||||
}
|
||||
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `&_`
|
||||
ref _x if false => {}
|
||||
"hello" => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/issue-30240.rs:2:11
|
||||
|
|
||||
LL | match "world" {
|
||||
| ^^^^^^^ pattern `&_` 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 `&str`
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/issue-30240.rs:6:11
|
||||
|
|
||||
LL | match "world" {
|
||||
| ^^^^^^^ pattern `&_` 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 `&str`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
match () { } //~ ERROR non-exhaustive
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: type `()` is non-empty
|
||||
--> $DIR/issue-3096-1.rs:2:11
|
||||
|
|
||||
LL | match () { }
|
||||
| ^^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
= note: the matched value is of type `()`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
enum Bottom { }
|
||||
|
||||
fn main() {
|
||||
let x = &() as *const () as *const Bottom;
|
||||
match x { } //~ ERROR non-exhaustive patterns
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: type `*const Bottom` is non-empty
|
||||
--> $DIR/issue-3096-2.rs:5:11
|
||||
|
|
||||
LL | match x { }
|
||||
| ^
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
= note: the matched value is of type `*const Bottom`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(non_snake_case)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Enum {
|
||||
Var1,
|
||||
Var2,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use Enum::*;
|
||||
let s = Var1;
|
||||
match s {
|
||||
Var1 => (),
|
||||
Var3 => (),
|
||||
Var2 => (),
|
||||
//~^ ERROR unreachable pattern
|
||||
};
|
||||
match &s {
|
||||
&Var1 => (),
|
||||
&Var3 => (),
|
||||
&Var2 => (),
|
||||
//~^ ERROR unreachable pattern
|
||||
};
|
||||
let t = (Var1, Var1);
|
||||
match t {
|
||||
(Var1, b) => (),
|
||||
(c, d) => (),
|
||||
anything => ()
|
||||
//~^ ERROR unreachable pattern
|
||||
};
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-31221.rs:18:9
|
||||
|
|
||||
LL | Var3 => (),
|
||||
| ---- matches any value
|
||||
LL | Var2 => (),
|
||||
| ^^^^ unreachable pattern
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-31221.rs:4:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/issue-31221.rs:24:9
|
||||
|
|
||||
LL | &Var3 => (),
|
||||
| ----- matches any value
|
||||
LL | &Var2 => (),
|
||||
| ^^^^^ unreachable pattern
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/issue-31221.rs:31:9
|
||||
|
|
||||
LL | (c, d) => (),
|
||||
| ------ matches any value
|
||||
LL | anything => ()
|
||||
| ^^^^^^^^ unreachable pattern
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
enum Thing {
|
||||
Foo(u8),
|
||||
Bar,
|
||||
Baz
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let Thing::Foo(y) = Thing::Foo(1);
|
||||
//~^ ERROR refutable pattern in local binding: `Bar` and `Baz` not covered
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
error[E0005]: refutable pattern in local binding: `Bar` and `Baz` not covered
|
||||
--> $DIR/issue-31561.rs:8:9
|
||||
|
|
||||
LL | / enum Thing {
|
||||
LL | | Foo(u8),
|
||||
LL | | Bar,
|
||||
| | --- not covered
|
||||
LL | | Baz
|
||||
| | --- not covered
|
||||
LL | | }
|
||||
| |_- `Thing` defined here
|
||||
...
|
||||
LL | let Thing::Foo(y) = Thing::Foo(1);
|
||||
| ^^^^^^^^^^^^^ patterns `Bar` and `Baz` not covered
|
||||
|
|
||||
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
|
||||
= note: the matched value is of type `Thing`
|
||||
help: you might want to use `if let` to ignore the variant that isn't matched
|
||||
|
|
||||
LL | if let Thing::Foo(y) = Thing::Foo(1) { /* */ }
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0005`.
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
|
||||
struct HTMLImageData {
|
||||
image: Option<String>
|
||||
}
|
||||
|
||||
struct ElementData {
|
||||
kind: Box<ElementKind>
|
||||
}
|
||||
|
||||
enum ElementKind {
|
||||
HTMLImageElement(HTMLImageData)
|
||||
}
|
||||
|
||||
enum NodeKind {
|
||||
Element(ElementData)
|
||||
}
|
||||
|
||||
struct NodeData {
|
||||
kind: Box<NodeKind>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut id = HTMLImageData { image: None };
|
||||
let ed = ElementData { kind: box ElementKind::HTMLImageElement(id) };
|
||||
let n = NodeData {kind : box NodeKind::Element(ed)};
|
||||
// n.b. span could be better
|
||||
match n.kind {
|
||||
box NodeKind::Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns
|
||||
box ElementKind::HTMLImageElement(ref d) if d.image.is_some() => { true }
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `Box(_, _)` not covered
|
||||
--> $DIR/issue-3601.rs:30:44
|
||||
|
|
||||
LL | box NodeKind::Element(ed) => match ed.kind {
|
||||
| ^^^^^^^ pattern `Box(_, _)` 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 `Box<ElementKind>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
enum Foo {
|
||||
Bar { bar: Bar, id: usize }
|
||||
}
|
||||
|
||||
enum Bar {
|
||||
A, B, C, D, E, F
|
||||
}
|
||||
|
||||
fn test(f: Foo) {
|
||||
match f {
|
||||
//~^ ERROR non-exhaustive patterns
|
||||
//~| patterns
|
||||
Foo::Bar { bar: Bar::A, .. } => (),
|
||||
Foo::Bar { bar: Bar::B, .. } => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `Bar { bar: C, .. }`, `Bar { bar: D, .. }`, `Bar { bar: E, .. }` and 1 more not covered
|
||||
--> $DIR/issue-39362.rs:10:11
|
||||
|
|
||||
LL | / enum Foo {
|
||||
LL | | Bar { bar: Bar, id: usize }
|
||||
LL | | }
|
||||
| |_- `Foo` defined here
|
||||
...
|
||||
LL | match f {
|
||||
| ^ patterns `Bar { bar: C, .. }`, `Bar { bar: D, .. }`, `Bar { bar: E, .. }` and 1 more 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`.
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fn main() {
|
||||
let tup = (true, true);
|
||||
println!("foo {:}", match tup { //~ ERROR non-exhaustive patterns: `(true, false)` not covered
|
||||
(false, false) => "foo",
|
||||
(false, true) => "bar",
|
||||
(true, true) => "baz"
|
||||
});
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0004]: non-exhaustive patterns: `(true, false)` not covered
|
||||
--> $DIR/issue-4321.rs:3:31
|
||||
|
|
||||
LL | println!("foo {:}", match tup {
|
||||
| ^^^ pattern `(true, 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 `(bool, bool)`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#![crate_type="lib"]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
mod test_struct {
|
||||
// Test the exact copy of the minimal example
|
||||
// posted in the issue.
|
||||
pub struct Punned {
|
||||
foo: [u8; 1],
|
||||
bar: [u8; 1],
|
||||
}
|
||||
|
||||
pub fn test(punned: Punned) {
|
||||
match punned {
|
||||
Punned { foo: [_], .. } => println!("foo"),
|
||||
Punned { bar: [_], .. } => println!("bar"),
|
||||
//~^ ERROR unreachable pattern [unreachable_patterns]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod test_union {
|
||||
// Test the same thing using a union.
|
||||
pub union Punned {
|
||||
foo: [u8; 1],
|
||||
bar: [u8; 1],
|
||||
}
|
||||
|
||||
pub fn test(punned: Punned) {
|
||||
match punned {
|
||||
Punned { foo: [_] } => println!("foo"),
|
||||
Punned { bar: [_] } => println!("bar"),
|
||||
//~^ ERROR unreachable pattern [unreachable_patterns]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/issue-57472.rs:15:13
|
||||
|
|
||||
LL | Punned { bar: [_], .. } => println!("bar"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-57472.rs:2:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unreachable pattern
|
||||
--> $DIR/issue-57472.rs:31:13
|
||||
|
|
||||
LL | Punned { bar: [_] } => println!("bar"),
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue