add test ensuring a moved mutex deadlocks

This commit is contained in:
Ralf Jung 2024-10-14 21:36:37 +02:00
parent d3c1036255
commit af98424285
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,16 @@
//@error-in-other-file: deadlock
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE"
//@normalize-stderr-test: "LL \| .*" -> "LL | $$CODE"
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "\n *= note:.*" -> ""
use std::mem;
use std::sync::Mutex;
fn main() {
let m = Mutex::new(0);
mem::forget(m.lock());
// Move the lock while it is "held" (really: leaked)
let m2 = m;
// Now try to acquire the lock again.
let _guard = m2.lock();
}

View File

@ -0,0 +1,16 @@
error: deadlock: the evaluated program deadlocked
--> RUSTLIB/std/$FILE:LL:CC
|
LL | $CODE
| ^ the evaluated program deadlocked
|
note: inside `main`
--> tests/fail/concurrency/mutex-leak-move-deadlock.rs:LL:CC
|
LL | $CODE
| ^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error