From 5df6af49a7dbec08f210e258c3a66301f4fb3535 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Dec 2018 12:54:49 +0100 Subject: [PATCH] Update tests to show diagnostics --- src/test/run-pass/ctfe/references.rs | 2 +- src/test/ui/pattern/const-pat-ice.rs | 13 +++++ src/test/ui/pattern/slice-pattern-const-2.rs | 10 ++-- .../ui/pattern/slice-pattern-const-2.stderr | 26 +++++++++ src/test/ui/pattern/slice-pattern-const-3.rs | 10 ++-- .../ui/pattern/slice-pattern-const-3.stderr | 14 +++++ src/test/ui/pattern/slice-pattern-const.rs | 18 +++--- .../ui/pattern/slice-pattern-const.stderr | 56 +++++++++++++++++++ 8 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 src/test/ui/pattern/const-pat-ice.rs create mode 100644 src/test/ui/pattern/slice-pattern-const-2.stderr create mode 100644 src/test/ui/pattern/slice-pattern-const-3.stderr create mode 100644 src/test/ui/pattern/slice-pattern-const.stderr diff --git a/src/test/run-pass/ctfe/references.rs b/src/test/run-pass/ctfe/references.rs index d5ab8dd7a2aa..421f35438302 100644 --- a/src/test/run-pass/ctfe/references.rs +++ b/src/test/run-pass/ctfe/references.rs @@ -31,7 +31,7 @@ fn main() { #[allow(unreachable_patterns)] match &43 { &42 => panic!(), - BOO => panic!(), // pattern is unreachable + BOO => panic!(), _ => println!("d"), } } diff --git a/src/test/ui/pattern/const-pat-ice.rs b/src/test/ui/pattern/const-pat-ice.rs new file mode 100644 index 000000000000..6496a2ab69f5 --- /dev/null +++ b/src/test/ui/pattern/const-pat-ice.rs @@ -0,0 +1,13 @@ +// failure-status: 101 + +// This is a repro test for an ICE in our pattern handling of constants. + +const FOO: &&&u32 = &&&42; + +fn main() { + match unimplemented!() { + &&&42 => {}, + FOO => {}, + _ => {}, + } +} diff --git a/src/test/ui/pattern/slice-pattern-const-2.rs b/src/test/ui/pattern/slice-pattern-const-2.rs index 15c23b39b01f..6cfef115d08d 100644 --- a/src/test/ui/pattern/slice-pattern-const-2.rs +++ b/src/test/ui/pattern/slice-pattern-const-2.rs @@ -1,4 +1,4 @@ -// compile-pass +#![deny(unreachable_patterns)] fn main() { let s = &[0x00; 4][..]; //Slice of any value @@ -6,26 +6,26 @@ fn main() { match s { MAGIC_TEST => (), [0x00, 0x00, 0x00, 0x00] => (), - [4, 5, 6, 7] => (), // this should warn + [4, 5, 6, 7] => (), //~ ERROR unreachable pattern _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), MAGIC_TEST => (), - [4, 5, 6, 7] => (), // this should warn + [4, 5, 6, 7] => (), //~ ERROR unreachable pattern _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), [4, 5, 6, 7] => (), - MAGIC_TEST => (), // this should warn + MAGIC_TEST => (), // FIXME(oli-obk): this should warn, but currently does not _ => (), } const FOO: [u32; 1] = [4]; match [99] { [0x00] => (), [4] => (), - FOO => (), // this should warn + FOO => (), //~ ERROR unreachable pattern _ => (), } } diff --git a/src/test/ui/pattern/slice-pattern-const-2.stderr b/src/test/ui/pattern/slice-pattern-const-2.stderr new file mode 100644 index 000000000000..95651ccc401e --- /dev/null +++ b/src/test/ui/pattern/slice-pattern-const-2.stderr @@ -0,0 +1,26 @@ +error: unreachable pattern + --> $DIR/slice-pattern-const-2.rs:9:9 + | +LL | [4, 5, 6, 7] => (), //~ ERROR unreachable pattern + | ^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/slice-pattern-const-2.rs:1:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const-2.rs:15:9 + | +LL | [4, 5, 6, 7] => (), //~ ERROR unreachable pattern + | ^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const-2.rs:28:9 + | +LL | FOO => (), //~ ERROR unreachable pattern + | ^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/pattern/slice-pattern-const-3.rs b/src/test/ui/pattern/slice-pattern-const-3.rs index dbc61af16b56..8805c43ba028 100644 --- a/src/test/ui/pattern/slice-pattern-const-3.rs +++ b/src/test/ui/pattern/slice-pattern-const-3.rs @@ -1,4 +1,4 @@ -// compile-pass +#![deny(unreachable_patterns)] fn main() { let s = &["0x00"; 4][..]; //Slice of any value @@ -6,26 +6,26 @@ fn main() { match s { MAGIC_TEST => (), ["0x00", "0x00", "0x00", "0x00"] => (), - ["4", "5", "6", "7"] => (), // this should warn + ["4", "5", "6", "7"] => (), // FIXME(oli-obk): this should warn, but currently does not _ => (), } match s { ["0x00", "0x00", "0x00", "0x00"] => (), MAGIC_TEST => (), - ["4", "5", "6", "7"] => (), // this should warn + ["4", "5", "6", "7"] => (), // FIXME(oli-obk): this should warn, but currently does not _ => (), } match s { ["0x00", "0x00", "0x00", "0x00"] => (), ["4", "5", "6", "7"] => (), - MAGIC_TEST => (), // this should warn + MAGIC_TEST => (), // FIXME(oli-obk): this should warn, but currently does not _ => (), } const FOO: [&str; 1] = ["boo"]; match ["baa"] { ["0x00"] => (), ["boo"] => (), - FOO => (), // this should warn + FOO => (), //~ ERROR unreachable pattern _ => (), } } diff --git a/src/test/ui/pattern/slice-pattern-const-3.stderr b/src/test/ui/pattern/slice-pattern-const-3.stderr new file mode 100644 index 000000000000..531bbbc84d03 --- /dev/null +++ b/src/test/ui/pattern/slice-pattern-const-3.stderr @@ -0,0 +1,14 @@ +error: unreachable pattern + --> $DIR/slice-pattern-const-3.rs:28:9 + | +LL | FOO => (), //~ ERROR unreachable pattern + | ^^^ + | +note: lint level defined here + --> $DIR/slice-pattern-const-3.rs:1:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/pattern/slice-pattern-const.rs b/src/test/ui/pattern/slice-pattern-const.rs index e2589ddf81c6..f0a04513f91f 100644 --- a/src/test/ui/pattern/slice-pattern-const.rs +++ b/src/test/ui/pattern/slice-pattern-const.rs @@ -1,4 +1,4 @@ -//compile-pass +#![deny(unreachable_patterns)] fn main() { let s = &[0x00; 4][..]; //Slice of any value @@ -6,33 +6,33 @@ fn main() { match s { MAGIC_TEST => (), [0x00, 0x00, 0x00, 0x00] => (), - [84, 69, 83, 84] => (), // this should warn + [84, 69, 83, 84] => (), //~ ERROR unreachable pattern _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), MAGIC_TEST => (), - [84, 69, 83, 84] => (), // this should warn + [84, 69, 83, 84] => (), //~ ERROR unreachable pattern _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), [84, 69, 83, 84] => (), - MAGIC_TEST => (), // this should warn + MAGIC_TEST => (), //~ ERROR unreachable pattern _ => (), } const FOO: [u8; 1] = [4]; match [99] { [0x00] => (), [4] => (), - FOO => (), // this should warn + FOO => (), //~ ERROR unreachable pattern _ => (), } const BAR: &[u8; 1] = &[4]; match &[99] { [0x00] => (), [4] => (), - BAR => (), // this should warn + BAR => (), //~ ERROR unreachable pattern b"a" => (), _ => (), } @@ -40,8 +40,8 @@ fn main() { const BOO: &[u8; 0] = &[]; match &[] { [] => (), - BOO => (), // this should warn - b"" => (), - _ => (), + BOO => (), //~ ERROR unreachable pattern + b"" => (), //~ ERROR unreachable pattern + _ => (), //~ ERROR unreachable pattern } } diff --git a/src/test/ui/pattern/slice-pattern-const.stderr b/src/test/ui/pattern/slice-pattern-const.stderr new file mode 100644 index 000000000000..412e0158c01c --- /dev/null +++ b/src/test/ui/pattern/slice-pattern-const.stderr @@ -0,0 +1,56 @@ +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:9:9 + | +LL | [84, 69, 83, 84] => (), //~ ERROR unreachable pattern + | ^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/slice-pattern-const.rs:1:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:15:9 + | +LL | [84, 69, 83, 84] => (), //~ ERROR unreachable pattern + | ^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:21:9 + | +LL | MAGIC_TEST => (), //~ ERROR unreachable pattern + | ^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:28:9 + | +LL | FOO => (), //~ ERROR unreachable pattern + | ^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:35:9 + | +LL | BAR => (), //~ ERROR unreachable pattern + | ^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:43:9 + | +LL | BOO => (), //~ ERROR unreachable pattern + | ^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:44:9 + | +LL | b"" => (), //~ ERROR unreachable pattern + | ^^^ + +error: unreachable pattern + --> $DIR/slice-pattern-const.rs:45:9 + | +LL | _ => (), //~ ERROR unreachable pattern + | ^ + +error: aborting due to 8 previous errors +