Skip to content

Commit 4d33225

Browse files
author
Daniel Smith
committed
Separate tests for each lint
1 parent 86f2b29 commit 4d33225

6 files changed

+309
-301
lines changed

tests/ui/await_holding_invalid.rs

-145
This file was deleted.

tests/ui/await_holding_invalid.stderr

-156
This file was deleted.

tests/ui/await_holding_lock.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// edition:2018
2+
#![warn(clippy::await_holding_lock)]
3+
4+
use std::sync::Mutex;
5+
6+
async fn bad(x: &Mutex<u32>) -> u32 {
7+
let guard = x.lock().unwrap();
8+
baz().await
9+
}
10+
11+
async fn good(x: &Mutex<u32>) -> u32 {
12+
{
13+
let guard = x.lock().unwrap();
14+
let y = *guard + 1;
15+
}
16+
baz().await;
17+
let guard = x.lock().unwrap();
18+
47
19+
}
20+
21+
async fn baz() -> u32 {
22+
42
23+
}
24+
25+
async fn also_bad(x: &Mutex<u32>) -> u32 {
26+
let first = baz().await;
27+
28+
let guard = x.lock().unwrap();
29+
30+
let second = baz().await;
31+
32+
let third = baz().await;
33+
34+
first + second + third
35+
}
36+
37+
async fn not_good(x: &Mutex<u32>) -> u32 {
38+
let first = baz().await;
39+
40+
let second = {
41+
let guard = x.lock().unwrap();
42+
baz().await
43+
};
44+
45+
let third = baz().await;
46+
47+
first + second + third
48+
}
49+
50+
#[allow(clippy::manual_async_fn)]
51+
fn block_bad(x: &Mutex<u32>) -> impl std::future::Future<Output = u32> + '_ {
52+
async move {
53+
let guard = x.lock().unwrap();
54+
baz().await
55+
}
56+
}
57+
58+
fn main() {
59+
let m = Mutex::new(100);
60+
good(&m);
61+
bad(&m);
62+
also_bad(&m);
63+
not_good(&m);
64+
block_bad(&m);
65+
}

0 commit comments

Comments
 (0)