mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Separate tests for each lint
This commit is contained in:
parent
86f2b29d2f
commit
4d3322525d
6 changed files with 309 additions and 301 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
65
tests/ui/await_holding_lock.rs
Normal file
65
tests/ui/await_holding_lock.rs
Normal file
|
@ -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);
|
||||
}
|
63
tests/ui/await_holding_lock.stderr
Normal file
63
tests/ui/await_holding_lock.stderr
Normal file
|
@ -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
|
||||
|
86
tests/ui/await_holding_refcell_ref.rs
Normal file
86
tests/ui/await_holding_refcell_ref.rs
Normal file
|
@ -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);
|
||||
}
|
95
tests/ui/await_holding_refcell_ref.stderr
Normal file
95
tests/ui/await_holding_refcell_ref.stderr
Normal file
|
@ -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
|
||||
|
Loading…
Reference in a new issue