Add tests

This commit is contained in:
Nadrieril 2021-08-25 22:58:49 +02:00
parent e0c38af27c
commit bf1848d8a5
3 changed files with 45 additions and 0 deletions

View File

@ -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, .. } => {}
_ => {}
}
}

View File

@ -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<()>;
}

View File

@ -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`.