]> git.lizzy.rs Git - rust.git/commitdiff
Separate tests for each lint
authorDaniel Smith <daniel.smith@datadoghq.com>
Mon, 19 Oct 2020 16:07:04 +0000 (12:07 -0400)
committerDaniel Smith <daniel.smith@datadoghq.com>
Wed, 21 Oct 2020 15:04:26 +0000 (11:04 -0400)
tests/ui/await_holding_invalid.rs [deleted file]
tests/ui/await_holding_invalid.stderr [deleted file]
tests/ui/await_holding_lock.rs [new file with mode: 0644]
tests/ui/await_holding_lock.stderr [new file with mode: 0644]
tests/ui/await_holding_refcell_ref.rs [new file with mode: 0644]
tests/ui/await_holding_refcell_ref.stderr [new file with mode: 0644]

diff --git a/tests/ui/await_holding_invalid.rs b/tests/ui/await_holding_invalid.rs
deleted file mode 100644 (file)
index 45aa3e6..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-// edition:2018
-#![warn(clippy::await_holding_lock, clippy::await_holding_refcell_ref)]
-
-use std::cell::RefCell;
-use std::sync::Mutex;
-
-async fn bad_lock(x: &Mutex<u32>) -> u32 {
-    let guard = x.lock().unwrap();
-    baz().await
-}
-
-async fn good_lock(x: &Mutex<u32>) -> u32 {
-    {
-        let guard = x.lock().unwrap();
-        let y = *guard + 1;
-    }
-    baz().await;
-    let guard = x.lock().unwrap();
-    47
-}
-
-async fn baz() -> u32 {
-    42
-}
-
-async fn also_bad_lock(x: &Mutex<u32>) -> u32 {
-    let first = baz().await;
-
-    let guard = x.lock().unwrap();
-
-    let second = baz().await;
-
-    let third = baz().await;
-
-    first + second + third
-}
-
-async fn not_good_lock(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_lock(x: &Mutex<u32>) -> impl std::future::Future<Output = u32> + '_ {
-    async move {
-        let guard = x.lock().unwrap();
-        baz().await
-    }
-}
-
-async fn bad_refcell(x: &RefCell<u32>) -> u32 {
-    let b = x.borrow();
-    baz().await
-}
-
-async fn bad_mut_refcell(x: &RefCell<u32>) -> u32 {
-    let b = x.borrow_mut();
-    baz().await
-}
-
-async fn good_refcell(x: &RefCell<u32>) -> u32 {
-    {
-        let b = x.borrow_mut();
-        let y = *b + 1;
-    }
-    baz().await;
-    let b = x.borrow_mut();
-    47
-}
-
-async fn also_bad_refcell(x: &RefCell<u32>) -> u32 {
-    let first = baz().await;
-
-    let b = x.borrow_mut();
-
-    let second = baz().await;
-
-    let third = baz().await;
-
-    first + second + third
-}
-
-async fn less_bad_refcell(x: &RefCell<u32>) -> u32 {
-    let first = baz().await;
-
-    let b = x.borrow_mut();
-
-    let second = baz().await;
-
-    drop(b);
-
-    let third = baz().await;
-
-    first + second + third
-}
-
-async fn not_good_refcell(x: &RefCell<u32>) -> u32 {
-    let first = baz().await;
-
-    let second = {
-        let b = x.borrow_mut();
-        baz().await
-    };
-
-    let third = baz().await;
-
-    first + second + third
-}
-
-#[allow(clippy::manual_async_fn)]
-fn block_bad_refcell(x: &RefCell<u32>) -> impl std::future::Future<Output = u32> + '_ {
-    async move {
-        let b = x.borrow_mut();
-        baz().await
-    }
-}
-
-fn main() {
-    {
-        let m = Mutex::new(100);
-        good_lock(&m);
-        bad_lock(&m);
-        also_bad_lock(&m);
-        not_good_lock(&m);
-        block_bad_lock(&m);
-    }
-    {
-        let rc = RefCell::new(100);
-        good_refcell(&rc);
-        bad_refcell(&rc);
-        bad_mut_refcell(&rc);
-        also_bad_refcell(&rc);
-        less_bad_refcell(&rc);
-        not_good_refcell(&rc);
-        block_bad_refcell(&rc);
-    }
-}
diff --git a/tests/ui/await_holding_invalid.stderr b/tests/ui/await_holding_invalid.stderr
deleted file mode 100644 (file)
index c8d4982..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:8:9
-   |
-LL |     let guard = x.lock().unwrap();
-   |         ^^^^^
-   |
-   = note: `-D clippy::await-holding-lock` implied by `-D warnings`
-note: these are all the await points this lock is held through
-  --> $DIR/await_holding_invalid.rs:8:5
-   |
-LL | /     let guard = x.lock().unwrap();
-LL | |     baz().await
-LL | | }
-   | |_^
-
-error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:29:9
-   |
-LL |     let guard = x.lock().unwrap();
-   |         ^^^^^
-   |
-note: these are all the await points this lock is held through
-  --> $DIR/await_holding_invalid.rs:29:5
-   |
-LL | /     let guard = x.lock().unwrap();
-LL | |
-LL | |     let second = baz().await;
-LL | |
-...  |
-LL | |     first + second + third
-LL | | }
-   | |_^
-
-error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:42:13
-   |
-LL |         let guard = x.lock().unwrap();
-   |             ^^^^^
-   |
-note: these are all the await points this lock is held through
-  --> $DIR/await_holding_invalid.rs:42:9
-   |
-LL | /         let guard = x.lock().unwrap();
-LL | |         baz().await
-LL | |     };
-   | |_____^
-
-error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:54:13
-   |
-LL |         let guard = x.lock().unwrap();
-   |             ^^^^^
-   |
-note: these are all the await points this lock is held through
-  --> $DIR/await_holding_invalid.rs:54:9
-   |
-LL | /         let guard = x.lock().unwrap();
-LL | |         baz().await
-LL | |     }
-   | |_____^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:60:9
-   |
-LL |     let b = x.borrow();
-   |         ^
-   |
-   = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:60:5
-   |
-LL | /     let b = x.borrow();
-LL | |     baz().await
-LL | | }
-   | |_^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:65:9
-   |
-LL |     let b = x.borrow_mut();
-   |         ^
-   |
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:65:5
-   |
-LL | /     let b = x.borrow_mut();
-LL | |     baz().await
-LL | | }
-   | |_^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:82:9
-   |
-LL |     let b = x.borrow_mut();
-   |         ^
-   |
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:82:5
-   |
-LL | /     let b = x.borrow_mut();
-LL | |
-LL | |     let second = baz().await;
-LL | |
-...  |
-LL | |     first + second + third
-LL | | }
-   | |_^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:94:9
-   |
-LL |     let b = x.borrow_mut();
-   |         ^
-   |
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:94:5
-   |
-LL | /     let b = x.borrow_mut();
-LL | |
-LL | |     let second = baz().await;
-LL | |
-...  |
-LL | |     first + second + third
-LL | | }
-   | |_^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:109:13
-   |
-LL |         let b = x.borrow_mut();
-   |             ^
-   |
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:109:9
-   |
-LL | /         let b = x.borrow_mut();
-LL | |         baz().await
-LL | |     };
-   | |_____^
-
-error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
-  --> $DIR/await_holding_invalid.rs:121:13
-   |
-LL |         let b = x.borrow_mut();
-   |             ^
-   |
-note: these are all the await points this ref is held through
-  --> $DIR/await_holding_invalid.rs:121:9
-   |
-LL | /         let b = x.borrow_mut();
-LL | |         baz().await
-LL | |     }
-   | |_____^
-
-error: aborting due to 10 previous errors
-
diff --git a/tests/ui/await_holding_lock.rs b/tests/ui/await_holding_lock.rs
new file mode 100644 (file)
index 0000000..0458950
--- /dev/null
@@ -0,0 +1,65 @@
+// edition:2018
+#![warn(clippy::await_holding_lock)]
+
+use std::sync::Mutex;
+
+async fn bad(x: &Mutex<u32>) -> u32 {
+    let guard = x.lock().unwrap();
+    baz().await
+}
+
+async fn good(x: &Mutex<u32>) -> u32 {
+    {
+        let guard = x.lock().unwrap();
+        let y = *guard + 1;
+    }
+    baz().await;
+    let guard = x.lock().unwrap();
+    47
+}
+
+async fn baz() -> u32 {
+    42
+}
+
+async fn also_bad(x: &Mutex<u32>) -> u32 {
+    let first = baz().await;
+
+    let guard = x.lock().unwrap();
+
+    let second = baz().await;
+
+    let third = baz().await;
+
+    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);
+}
diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr
new file mode 100644 (file)
index 0000000..21bf49d
--- /dev/null
@@ -0,0 +1,63 @@
+error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
+  --> $DIR/await_holding_lock.rs:7:9
+   |
+LL |     let guard = x.lock().unwrap();
+   |         ^^^^^
+   |
+   = note: `-D clippy::await-holding-lock` implied by `-D warnings`
+note: these are all the await points this lock is held through
+  --> $DIR/await_holding_lock.rs:7:5
+   |
+LL | /     let guard = x.lock().unwrap();
+LL | |     baz().await
+LL | | }
+   | |_^
+
+error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
+  --> $DIR/await_holding_lock.rs:28:9
+   |
+LL |     let guard = x.lock().unwrap();
+   |         ^^^^^
+   |
+note: these are all the await points this lock is held through
+  --> $DIR/await_holding_lock.rs:28:5
+   |
+LL | /     let guard = x.lock().unwrap();
+LL | |
+LL | |     let second = baz().await;
+LL | |
+...  |
+LL | |     first + second + third
+LL | | }
+   | |_^
+
+error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
+  --> $DIR/await_holding_lock.rs:41:13
+   |
+LL |         let guard = x.lock().unwrap();
+   |             ^^^^^
+   |
+note: these are all the await points this lock is held through
+  --> $DIR/await_holding_lock.rs:41:9
+   |
+LL | /         let guard = x.lock().unwrap();
+LL | |         baz().await
+LL | |     };
+   | |_____^
+
+error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
+  --> $DIR/await_holding_lock.rs:53:13
+   |
+LL |         let guard = x.lock().unwrap();
+   |             ^^^^^
+   |
+note: these are all the await points this lock is held through
+  --> $DIR/await_holding_lock.rs:53:9
+   |
+LL | /         let guard = x.lock().unwrap();
+LL | |         baz().await
+LL | |     }
+   | |_____^
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/await_holding_refcell_ref.rs b/tests/ui/await_holding_refcell_ref.rs
new file mode 100644 (file)
index 0000000..8884159
--- /dev/null
@@ -0,0 +1,86 @@
+// edition:2018
+#![warn(clippy::await_holding_refcell_ref)]
+
+use std::cell::RefCell;
+
+async fn bad(x: &RefCell<u32>) -> u32 {
+    let b = x.borrow();
+    baz().await
+}
+
+async fn bad_mut(x: &RefCell<u32>) -> u32 {
+    let b = x.borrow_mut();
+    baz().await
+}
+
+async fn good(x: &RefCell<u32>) -> u32 {
+    {
+        let b = x.borrow_mut();
+        let y = *b + 1;
+    }
+    baz().await;
+    let b = x.borrow_mut();
+    47
+}
+
+async fn baz() -> u32 {
+    42
+}
+
+async fn also_bad(x: &RefCell<u32>) -> u32 {
+    let first = baz().await;
+
+    let b = x.borrow_mut();
+
+    let second = baz().await;
+
+    let third = baz().await;
+
+    first + second + third
+}
+
+async fn less_bad(x: &RefCell<u32>) -> u32 {
+    let first = baz().await;
+
+    let b = x.borrow_mut();
+
+    let second = baz().await;
+
+    drop(b);
+
+    let third = baz().await;
+
+    first + second + third
+}
+
+async fn not_good(x: &RefCell<u32>) -> u32 {
+    let first = baz().await;
+
+    let second = {
+        let b = x.borrow_mut();
+        baz().await
+    };
+
+    let third = baz().await;
+
+    first + second + third
+}
+
+#[allow(clippy::manual_async_fn)]
+fn block_bad(x: &RefCell<u32>) -> impl std::future::Future<Output = u32> + '_ {
+    async move {
+        let b = x.borrow_mut();
+        baz().await
+    }
+}
+
+fn main() {
+    let rc = RefCell::new(100);
+    good(&rc);
+    bad(&rc);
+    bad_mut(&rc);
+    also_bad(&rc);
+    less_bad(&rc);
+    not_good(&rc);
+    block_bad(&rc);
+}
diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr
new file mode 100644 (file)
index 0000000..b504f04
--- /dev/null
@@ -0,0 +1,95 @@
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:7:9
+   |
+LL |     let b = x.borrow();
+   |         ^
+   |
+   = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:7:5
+   |
+LL | /     let b = x.borrow();
+LL | |     baz().await
+LL | | }
+   | |_^
+
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:12:9
+   |
+LL |     let b = x.borrow_mut();
+   |         ^
+   |
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:12:5
+   |
+LL | /     let b = x.borrow_mut();
+LL | |     baz().await
+LL | | }
+   | |_^
+
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:33:9
+   |
+LL |     let b = x.borrow_mut();
+   |         ^
+   |
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:33:5
+   |
+LL | /     let b = x.borrow_mut();
+LL | |
+LL | |     let second = baz().await;
+LL | |
+...  |
+LL | |     first + second + third
+LL | | }
+   | |_^
+
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:45:9
+   |
+LL |     let b = x.borrow_mut();
+   |         ^
+   |
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:45:5
+   |
+LL | /     let b = x.borrow_mut();
+LL | |
+LL | |     let second = baz().await;
+LL | |
+...  |
+LL | |     first + second + third
+LL | | }
+   | |_^
+
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:60:13
+   |
+LL |         let b = x.borrow_mut();
+   |             ^
+   |
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:60:9
+   |
+LL | /         let b = x.borrow_mut();
+LL | |         baz().await
+LL | |     };
+   | |_____^
+
+error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
+  --> $DIR/await_holding_refcell_ref.rs:72:13
+   |
+LL |         let b = x.borrow_mut();
+   |             ^
+   |
+note: these are all the await points this ref is held through
+  --> $DIR/await_holding_refcell_ref.rs:72:9
+   |
+LL | /         let b = x.borrow_mut();
+LL | |         baz().await
+LL | |     }
+   | |_____^
+
+error: aborting due to 6 previous errors
+