]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/await_holding_lock.rs
Auto merge of #6336 - giraffate:sync-from-rust, r=flip1995
[rust.git] / tests / ui / await_holding_lock.rs
index fab31f37ffcc0039b6c3951db7e34a13a9429f92..0458950edee1c9660d41a4e15a974038f3949eac 100644 (file)
@@ -34,9 +34,32 @@ async fn also_bad(x: &Mutex<u32>) -> u32 {
     first + second + third
 }
 
+async fn not_good(x: &Mutex<u32>) -> u32 {
+    let first = baz().await;
+
+    let second = {
+        let guard = x.lock().unwrap();
+        baz().await
+    };
+
+    let third = baz().await;
+
+    first + second + third
+}
+
+#[allow(clippy::manual_async_fn)]
+fn block_bad(x: &Mutex<u32>) -> impl std::future::Future<Output = u32> + '_ {
+    async move {
+        let guard = x.lock().unwrap();
+        baz().await
+    }
+}
+
 fn main() {
     let m = Mutex::new(100);
     good(&m);
     bad(&m);
     also_bad(&m);
+    not_good(&m);
+    block_bad(&m);
 }