Skip to content

Commit af98424

Browse files
committed
add test ensuring a moved mutex deadlocks
1 parent d3c1036 commit af98424

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@error-in-other-file: deadlock
2+
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE"
3+
//@normalize-stderr-test: "LL \| .*" -> "LL | $$CODE"
4+
//@normalize-stderr-test: "\| +\^+" -> "| ^"
5+
//@normalize-stderr-test: "\n *= note:.*" -> ""
6+
use std::mem;
7+
use std::sync::Mutex;
8+
9+
fn main() {
10+
let m = Mutex::new(0);
11+
mem::forget(m.lock());
12+
// Move the lock while it is "held" (really: leaked)
13+
let m2 = m;
14+
// Now try to acquire the lock again.
15+
let _guard = m2.lock();
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: deadlock: the evaluated program deadlocked
2+
--> RUSTLIB/std/$FILE:LL:CC
3+
|
4+
LL | $CODE
5+
| ^ the evaluated program deadlocked
6+
|
7+
note: inside `main`
8+
--> tests/fail/concurrency/mutex-leak-move-deadlock.rs:LL:CC
9+
|
10+
LL | $CODE
11+
| ^
12+
13+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
14+
15+
error: aborting due to 1 previous error
16+

0 commit comments

Comments
 (0)