about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2022-02-12 11:30:03 +0100
committerflip1995 <philipp.krones@embecosm.com>2022-02-17 18:03:13 +0100
commitc5709419b1b31c8d4c5e369c7b9adbf592c599ca (patch)
tree29a02dda427fd6190293e882312b2a177ede2d4f
parentc4944fb60d102a4a4e0cb5f3f86379bea2338ed0 (diff)
downloadrust-c5709419b1b31c8d4c5e369c7b9adbf592c599ca.tar.gz
rust-c5709419b1b31c8d4c5e369c7b9adbf592c599ca.zip
Add test for drop-before-await FP
-rw-r--r--tests/ui/await_holding_lock.rs30
-rw-r--r--tests/ui/await_holding_lock.stderr67
2 files changed, 64 insertions, 33 deletions
diff --git a/tests/ui/await_holding_lock.rs b/tests/ui/await_holding_lock.rs
index 1a57db91ab5..57e5b55045b 100644
--- a/tests/ui/await_holding_lock.rs
+++ b/tests/ui/await_holding_lock.rs
@@ -2,6 +2,7 @@
 
 // When adding or modifying a test, please do the same for parking_lot::Mutex.
 mod std_mutex {
+    use super::baz;
     use std::sync::{Mutex, RwLock};
 
     pub async fn bad(x: &Mutex<u32>) -> u32 {
@@ -43,10 +44,6 @@ mod std_mutex {
         47
     }
 
-    pub async fn baz() -> u32 {
-        42
-    }
-
     pub async fn also_bad(x: &Mutex<u32>) -> u32 {
         let first = baz().await;
 
@@ -83,6 +80,7 @@ mod std_mutex {
 
 // When adding or modifying a test, please do the same for std::Mutex.
 mod parking_lot_mutex {
+    use super::baz;
     use parking_lot::{Mutex, RwLock};
 
     pub async fn bad(x: &Mutex<u32>) -> u32 {
@@ -124,10 +122,6 @@ mod parking_lot_mutex {
         47
     }
 
-    pub async fn baz() -> u32 {
-        42
-    }
-
     pub async fn also_bad(x: &Mutex<u32>) -> u32 {
         let first = baz().await;
 
@@ -162,6 +156,26 @@ mod parking_lot_mutex {
     }
 }
 
+async fn baz() -> u32 {
+    42
+}
+
+async fn no_await(x: std::sync::Mutex<u32>) {
+    let mut guard = x.lock().unwrap();
+    *guard += 1;
+}
+
+// FIXME: FP, because the `MutexGuard` is dropped before crossing the await point. This is
+// something the needs to be fixed in rustc. There's already drop-tracking, but this is currently
+// disabled, see rust-lang/rust#93751. This case isn't picked up by drop-tracking though. If the
+// `*guard += 1` is removed it is picked up.
+async fn dropped_before_await(x: std::sync::Mutex<u32>) {
+    let mut guard = x.lock().unwrap();
+    *guard += 1;
+    drop(guard);
+    baz().await;
+}
+
 fn main() {
     let m = std::sync::Mutex::new(100);
     std_mutex::good(&m);
diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr
index a6c1dd228e4..976da8d9242 100644
--- a/tests/ui/await_holding_lock.stderr
+++ b/tests/ui/await_holding_lock.stderr
@@ -1,5 +1,5 @@
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:8:13
+  --> $DIR/await_holding_lock.rs:9:13
    |
 LL |         let guard = x.lock().unwrap();
    |             ^^^^^
@@ -7,7 +7,7 @@ LL |         let guard = x.lock().unwrap();
    = note: `-D clippy::await-holding-lock` implied by `-D warnings`
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:8:9
+  --> $DIR/await_holding_lock.rs:9:9
    |
 LL | /         let guard = x.lock().unwrap();
 LL | |         baz().await
@@ -15,14 +15,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:23:13
+  --> $DIR/await_holding_lock.rs:24:13
    |
 LL |         let guard = x.read().unwrap();
    |             ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:23:9
+  --> $DIR/await_holding_lock.rs:24:9
    |
 LL | /         let guard = x.read().unwrap();
 LL | |         baz().await
@@ -30,14 +30,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:28:13
+  --> $DIR/await_holding_lock.rs:29:13
    |
 LL |         let mut guard = x.write().unwrap();
    |             ^^^^^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:28:9
+  --> $DIR/await_holding_lock.rs:29:9
    |
 LL | /         let mut guard = x.write().unwrap();
 LL | |         baz().await
@@ -45,14 +45,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:53:13
+  --> $DIR/await_holding_lock.rs:50:13
    |
 LL |         let guard = x.lock().unwrap();
    |             ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:53:9
+  --> $DIR/await_holding_lock.rs:50:9
    |
 LL | /         let guard = x.lock().unwrap();
 LL | |
@@ -64,14 +64,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:66:17
+  --> $DIR/await_holding_lock.rs:63:17
    |
 LL |             let guard = x.lock().unwrap();
    |                 ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:66:13
+  --> $DIR/await_holding_lock.rs:63:13
    |
 LL | /             let guard = x.lock().unwrap();
 LL | |             baz().await
@@ -79,14 +79,14 @@ LL | |         };
    | |_________^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:78:17
+  --> $DIR/await_holding_lock.rs:75:17
    |
 LL |             let guard = x.lock().unwrap();
    |                 ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:78:13
+  --> $DIR/await_holding_lock.rs:75:13
    |
 LL | /             let guard = x.lock().unwrap();
 LL | |             baz().await
@@ -94,14 +94,14 @@ LL | |         }
    | |_________^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:89:13
+  --> $DIR/await_holding_lock.rs:87:13
    |
 LL |         let guard = x.lock();
    |             ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:89:9
+  --> $DIR/await_holding_lock.rs:87:9
    |
 LL | /         let guard = x.lock();
 LL | |         baz().await
@@ -109,14 +109,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:104:13
+  --> $DIR/await_holding_lock.rs:102:13
    |
 LL |         let guard = x.read();
    |             ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:104:9
+  --> $DIR/await_holding_lock.rs:102:9
    |
 LL | /         let guard = x.read();
 LL | |         baz().await
@@ -124,14 +124,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:109:13
+  --> $DIR/await_holding_lock.rs:107:13
    |
 LL |         let mut guard = x.write();
    |             ^^^^^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:109:9
+  --> $DIR/await_holding_lock.rs:107:9
    |
 LL | /         let mut guard = x.write();
 LL | |         baz().await
@@ -139,14 +139,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:134:13
+  --> $DIR/await_holding_lock.rs:128:13
    |
 LL |         let guard = x.lock();
    |             ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:134:9
+  --> $DIR/await_holding_lock.rs:128:9
    |
 LL | /         let guard = x.lock();
 LL | |
@@ -158,14 +158,14 @@ LL | |     }
    | |_____^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:147:17
+  --> $DIR/await_holding_lock.rs:141:17
    |
 LL |             let guard = x.lock();
    |                 ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:147:13
+  --> $DIR/await_holding_lock.rs:141:13
    |
 LL | /             let guard = x.lock();
 LL | |             baz().await
@@ -173,19 +173,36 @@ LL | |         };
    | |_________^
 
 error: this `MutexGuard` is held across an `await` point
-  --> $DIR/await_holding_lock.rs:159:17
+  --> $DIR/await_holding_lock.rs:153:17
    |
 LL |             let guard = x.lock();
    |                 ^^^^^
    |
    = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
 note: these are all the `await` points this lock is held through
-  --> $DIR/await_holding_lock.rs:159:13
+  --> $DIR/await_holding_lock.rs:153:13
    |
 LL | /             let guard = x.lock();
 LL | |             baz().await
 LL | |         }
    | |_________^
 
-error: aborting due to 12 previous errors
+error: this `MutexGuard` is held across an `await` point
+  --> $DIR/await_holding_lock.rs:173:9
+   |
+LL |     let mut guard = x.lock().unwrap();
+   |         ^^^^^^^^^
+   |
+   = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
+note: these are all the `await` points this lock is held through
+  --> $DIR/await_holding_lock.rs:173:5
+   |
+LL | /     let mut guard = x.lock().unwrap();
+LL | |     *guard += 1;
+LL | |     drop(guard);
+LL | |     baz().await;
+LL | | }
+   | |_^
+
+error: aborting due to 13 previous errors