Skip to content

Commit 1ed43bf

Browse files
committed
test for forgetting locked mutex
1 parent e5022bf commit 1ed43bf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/pass/concurrency/sync_singlethread.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::hint;
2+
use std::mem;
23
use std::sync::atomic;
34
use std::sync::{Mutex, TryLockError};
45

56
fn main() {
67
test_mutex_stdlib();
8+
leak_mutex_guard();
79
test_rwlock_stdlib();
810
test_spin_loop_hint();
911
test_thread_yield_now();
@@ -19,6 +21,12 @@ fn test_mutex_stdlib() {
1921
drop(m);
2022
}
2123

24+
fn leak_mutex_guard() {
25+
// Test for https://github.com/rust-lang/rust/issues/85434
26+
let m = Mutex::new(5i32);
27+
mem::forget(m.lock());
28+
}
29+
2230
fn test_rwlock_stdlib() {
2331
use std::sync::RwLock;
2432
let rw = RwLock::new(0);

0 commit comments

Comments
 (0)