-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove hard-coded suggestion, add ui-toml test
- Loading branch information
Showing
6 changed files
with
197 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
blocking-ops = ["unnecessary_blocking_ops::blocking_mod::sleep"] | ||
blocking-ops-with-suggestions = [ | ||
["std::fs::remove_dir", "tokio::fs::remove_dir"], | ||
["std::fs::copy", "tokio::fs::copy"], | ||
["std::io::copy", "tokio::io::copy"], | ||
["std::io::read_to_string", "unnecessary_blocking_ops::async_mod::read_to_string"], | ||
["std::thread::sleep", "unnecessary_blocking_ops::async_mod::sleep"], | ||
] |
35 changes: 35 additions & 0 deletions
35
tests/ui-toml/unnecessary_blocking_ops/unnecessary_blocking_ops.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//@no-rustfix | ||
#![warn(clippy::unnecessary_blocking_ops)] | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
use std::{fs, io}; | ||
|
||
mod async_mod { | ||
pub async fn sleep(_dur: std::time::Duration) {} | ||
pub async fn read_to_string(mut reader: std::io::Stdin) -> Result<String, ()> { | ||
Ok(String::new()) | ||
} | ||
} | ||
|
||
mod blocking_mod { | ||
pub async fn sleep(_dur: std::time::Duration) {} | ||
} | ||
|
||
pub async fn async_fn() { | ||
sleep(Duration::from_secs(1)); | ||
//~^ ERROR: blocking function call detected in an async body | ||
fs::remove_dir("").unwrap(); | ||
//~^ ERROR: blocking function call detected in an async body | ||
fs::copy("", "_").unwrap(); | ||
//~^ ERROR: blocking function call detected in an async body | ||
let mut r: &[u8] = b"hello"; | ||
let mut w: Vec<u8> = vec![]; | ||
io::copy(&mut r, &mut w).unwrap(); | ||
//~^ ERROR: blocking function call detected in an async body | ||
let _cont = io::read_to_string(io::stdin()).unwrap(); | ||
//~^ ERROR: blocking function call detected in an async body | ||
fs::create_dir("").unwrap(); | ||
//~^ ERROR: blocking function call detected in an async body | ||
} | ||
|
||
fn main() {} |
51 changes: 51 additions & 0 deletions
51
tests/ui-toml/unnecessary_blocking_ops/unnecessary_blocking_ops.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:19:5 | ||
| | ||
LL | sleep(Duration::from_secs(1)); | ||
| ^^^^^------------------------ | ||
| | | ||
| help: try using its async counterpart: `unnecessary_blocking_ops::async_mod::sleep(Duration::from_secs(1)).await` | ||
| | ||
= note: `-D clippy::unnecessary-blocking-ops` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_blocking_ops)]` | ||
|
||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:21:5 | ||
| | ||
LL | fs::remove_dir("").unwrap(); | ||
| ^^^^^^^^^^^^^^---- | ||
| | | ||
| help: try using its async counterpart: `tokio::fs::remove_dir("").await` | ||
|
||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:23:5 | ||
| | ||
LL | fs::copy("", "_").unwrap(); | ||
| ^^^^^^^^--------- | ||
| | | ||
| help: try using its async counterpart: `tokio::fs::copy("", "_").await` | ||
|
||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:27:5 | ||
| | ||
LL | io::copy(&mut r, &mut w).unwrap(); | ||
| ^^^^^^^^---------------- | ||
| | | ||
| help: try using its async counterpart: `tokio::io::copy(&mut r, &mut w).await` | ||
|
||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:29:17 | ||
| | ||
LL | let _cont = io::read_to_string(io::stdin()).unwrap(); | ||
| ^^^^^^^^^^^^^^^^^^------------- | ||
| | | ||
| help: try using its async counterpart: `unnecessary_blocking_ops::async_mod::read_to_string(io::stdin()).await` | ||
|
||
error: blocking function call detected in an async body | ||
--> $DIR/unnecessary_blocking_ops.rs:31:5 | ||
| | ||
LL | fs::create_dir("").unwrap(); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.