2 Checks for calls to await while holding a non-async-aware MutexGuard.
5 The Mutex types found in std::sync and parking_lot
6 are not designed to operate in an async context across await points.
8 There are two potential solutions. One is to use an async-aware Mutex
9 type. Many asynchronous foundation crates provide such a Mutex type. The
10 other solution is to ensure the mutex is unlocked before calling await,
11 either by introducing a scope or an explicit call to Drop::drop.
14 Will report false positive for explicitly dropped guards
15 ([#6446](https://github.com/rust-lang/rust-clippy/issues/6446)). A workaround for this is
16 to wrap the `.lock()` call in a block instead of explicitly dropping the guard.
20 async fn foo(x: &Mutex<u32>) {
21 let mut guard = x.lock().unwrap();
26 async fn bar(x: &Mutex<u32>) {
27 let mut guard = x.lock().unwrap();
29 drop(guard); // explicit drop
36 async fn foo(x: &Mutex<u32>) {
38 let mut guard = x.lock().unwrap();
44 async fn bar(x: &Mutex<u32>) {
46 let mut guard = x.lock().unwrap();
48 } // guard dropped here at end of scope