diff options
| author | Ralf Jung <post@ralfj.de> | 2023-10-28 11:18:13 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-10-28 11:20:12 +0200 |
| commit | d17690065a7f4691926404a72c11c0694f020c66 (patch) | |
| tree | 1f557315ba3b44d6342100d254f79a239a78ef45 | |
| parent | 9b5b4dde92921275b9629a02132e2139d47a954b (diff) | |
| download | rust-d17690065a7f4691926404a72c11c0694f020c66.tar.gz rust-d17690065a7f4691926404a72c11c0694f020c66.zip | |
add some tests specifically for validity checks arising from match binders
4 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs new file mode 100644 index 00000000000..6c1df45ac0e --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs @@ -0,0 +1,15 @@ +fn main() { + #[derive(Copy, Clone)] + enum Void {} + union Uninit<T: Copy> { + value: T, + uninit: (), + } + unsafe { + let x: Uninit<Void> = Uninit { uninit: () }; + match x.value { + #[allow(unreachable_patterns)] + _x => println!("hi from the void!"), //~ERROR: invalid value + } + } +} diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr new file mode 100644 index 00000000000..c234467bddc --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: constructing invalid value: encountered a value of uninhabited type `main::Void` + --> $DIR/match_binder_checks_validity1.rs:LL:CC + | +LL | _x => println!("hi from the void!"), + | ^^ constructing invalid value: encountered a value of uninhabited type `main::Void` + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/match_binder_checks_validity1.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs new file mode 100644 index 00000000000..0517263a8f5 --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs @@ -0,0 +1,14 @@ +fn main() { + #[derive(Copy, Clone)] + union Uninit<T: Copy> { + value: T, + uninit: u8, + } + unsafe { + let x: Uninit<bool> = Uninit { uninit: 3 }; + match x.value { + #[allow(unreachable_patterns)] + _x => println!("hi from the void!"), //~ERROR: invalid value + } + } +} diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr new file mode 100644 index 00000000000..8af2d37d74a --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: constructing invalid value: encountered 0x03, but expected a boolean + --> $DIR/match_binder_checks_validity2.rs:LL:CC + | +LL | _x => println!("hi from the void!"), + | ^^ constructing invalid value: encountered 0x03, but expected a boolean + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/match_binder_checks_validity2.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + |
