From bf1848d8a58e5ed70b016bc1039ca26e9941b6e8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 25 Aug 2021 22:58:49 +0200 Subject: [PATCH] Add tests --- .../usefulness/const-private-fields.rs | 30 +++++++++++++++++++ .../issue-82772-match-box-as-struct.rs | 6 ++++ .../issue-82772-match-box-as-struct.stderr | 9 ++++++ 3 files changed, 45 insertions(+) create mode 100644 src/test/ui/pattern/usefulness/const-private-fields.rs create mode 100644 src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.rs create mode 100644 src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr diff --git a/src/test/ui/pattern/usefulness/const-private-fields.rs b/src/test/ui/pattern/usefulness/const-private-fields.rs new file mode 100644 index 00000000000..06c832ca46a --- /dev/null +++ b/src/test/ui/pattern/usefulness/const-private-fields.rs @@ -0,0 +1,30 @@ +// check-pass +// +// Check that we don't ignore private fields in usefulness checking +#![deny(unreachable_patterns)] + +mod inner { + #[derive(PartialEq, Eq)] + pub struct PrivateField { + pub x: bool, + y: bool, + } + + pub const FOO: PrivateField = PrivateField { x: true, y: true }; + pub const BAR: PrivateField = PrivateField { x: true, y: false }; +} +use inner::*; + +fn main() { + match FOO { + FOO => {} + BAR => {} + _ => {} + } + + match FOO { + FOO => {} + PrivateField { x: true, .. } => {} + _ => {} + } +} diff --git a/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.rs b/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.rs new file mode 100644 index 00000000000..c1bfcc73402 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.rs @@ -0,0 +1,6 @@ +// This used to ICE in exhaustiveness checking. Explanation here: +// https://github.com/rust-lang/rust/issues/82772#issuecomment-905946768 +fn main() { + let Box { 1: _, .. }: Box<()>; //~ ERROR field `1` of + let Box { .. }: Box<()>; +} diff --git a/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr b/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr new file mode 100644 index 00000000000..2c8c85bb1e0 --- /dev/null +++ b/src/test/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr @@ -0,0 +1,9 @@ +error[E0451]: field `1` of struct `Box` is private + --> $DIR/issue-82772-match-box-as-struct.rs:4:15 + | +LL | let Box { 1: _, .. }: Box<()>; + | ^^^^ private field + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0451`.