Skip to content

Commit 507fc23

Browse files
committed
add some tests specifically for validity checks arising from match binders
1 parent ea060ce commit 507fc23

4 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn main() {
2+
#[derive(Copy, Clone)]
3+
enum Void {}
4+
union Uninit<T: Copy> {
5+
value: T,
6+
uninit: (),
7+
}
8+
unsafe {
9+
let x: Uninit<Void> = Uninit { uninit: () };
10+
match x.value {
11+
#[allow(unreachable_patterns)]
12+
_x => println!("hi from the void!"), //~ERROR: invalid value
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: constructing invalid value: encountered a value of uninhabited type `main::Void`
2+
--> $DIR/match_binder_checks_validity1.rs:LL:CC
3+
|
4+
LL | _x => println!("hi from the void!"),
5+
| ^^ constructing invalid value: encountered a value of uninhabited type `main::Void`
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/match_binder_checks_validity1.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {
2+
#[derive(Copy, Clone)]
3+
union Uninit<T: Copy> {
4+
value: T,
5+
uninit: u8,
6+
}
7+
unsafe {
8+
let x: Uninit<bool> = Uninit { uninit: 3 };
9+
match x.value {
10+
#[allow(unreachable_patterns)]
11+
_x => println!("hi from the void!"), //~ERROR: invalid value
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: constructing invalid value: encountered 0x03, but expected a boolean
2+
--> $DIR/match_binder_checks_validity2.rs:LL:CC
3+
|
4+
LL | _x => println!("hi from the void!"),
5+
| ^^ constructing invalid value: encountered 0x03, but expected a boolean
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/match_binder_checks_validity2.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)