add large future lint
This commit is contained in:
parent
ba7fd68e87
commit
4fdae81c70
13 changed files with 292 additions and 1 deletions
1
tests/ui-toml/large_futures/clippy.toml
Normal file
1
tests/ui-toml/large_futures/clippy.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
future-size-threshold = 1024
|
||||
29
tests/ui-toml/large_futures/large_futures.fixed
Normal file
29
tests/ui-toml/large_futures/large_futures.fixed
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::large_futures)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
pub async fn should_warn() {
|
||||
let x = [0u8; 1024];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
pub async fn should_not_warn() {
|
||||
let x = [0u8; 1020];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
pub async fn bar() {
|
||||
Box::pin(should_warn()).await;
|
||||
|
||||
async {
|
||||
let x = [0u8; 1024];
|
||||
dbg!(x);
|
||||
}
|
||||
.await;
|
||||
|
||||
should_not_warn().await;
|
||||
}
|
||||
29
tests/ui-toml/large_futures/large_futures.rs
Normal file
29
tests/ui-toml/large_futures/large_futures.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::large_futures)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
pub async fn should_warn() {
|
||||
let x = [0u8; 1024];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
pub async fn should_not_warn() {
|
||||
let x = [0u8; 1020];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
pub async fn bar() {
|
||||
should_warn().await;
|
||||
|
||||
async {
|
||||
let x = [0u8; 1024];
|
||||
dbg!(x);
|
||||
}
|
||||
.await;
|
||||
|
||||
should_not_warn().await;
|
||||
}
|
||||
10
tests/ui-toml/large_futures/large_futures.stderr
Normal file
10
tests/ui-toml/large_futures/large_futures.stderr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
error: large future with a size of 1026 bytes
|
||||
--> $DIR/large_futures.rs:20:5
|
||||
|
|
||||
LL | should_warn().await;
|
||||
| ^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(should_warn())`
|
||||
|
|
||||
= note: `-D clippy::large-futures` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -24,6 +24,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
|
|||
enforced-import-renames
|
||||
enum-variant-name-threshold
|
||||
enum-variant-size-threshold
|
||||
future-size-threshold
|
||||
ignore-interior-mutability
|
||||
large-error-threshold
|
||||
literal-representation-threshold
|
||||
|
|
|
|||
41
tests/ui/large_futures.fixed
Normal file
41
tests/ui/large_futures.fixed
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// run-rustfix
|
||||
|
||||
#![feature(generators)]
|
||||
#![warn(clippy::large_futures)]
|
||||
#![allow(clippy::future_not_send)]
|
||||
#![allow(clippy::manual_async_fn)]
|
||||
|
||||
async fn big_fut(_arg: [u8; 1024 * 16]) {}
|
||||
|
||||
async fn wait() {
|
||||
let f = async {
|
||||
Box::pin(big_fut([0u8; 1024 * 16])).await;
|
||||
};
|
||||
Box::pin(f).await
|
||||
}
|
||||
async fn calls_fut(fut: impl std::future::Future<Output = ()>) {
|
||||
loop {
|
||||
Box::pin(wait()).await;
|
||||
if true {
|
||||
return fut.await;
|
||||
} else {
|
||||
Box::pin(wait()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test() {
|
||||
let fut = big_fut([0u8; 1024 * 16]);
|
||||
Box::pin(foo()).await;
|
||||
Box::pin(calls_fut(fut)).await;
|
||||
}
|
||||
|
||||
pub fn foo() -> impl std::future::Future<Output = ()> {
|
||||
async {
|
||||
let x = [0i32; 1024 * 16];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
41
tests/ui/large_futures.rs
Normal file
41
tests/ui/large_futures.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// run-rustfix
|
||||
|
||||
#![feature(generators)]
|
||||
#![warn(clippy::large_futures)]
|
||||
#![allow(clippy::future_not_send)]
|
||||
#![allow(clippy::manual_async_fn)]
|
||||
|
||||
async fn big_fut(_arg: [u8; 1024 * 16]) {}
|
||||
|
||||
async fn wait() {
|
||||
let f = async {
|
||||
big_fut([0u8; 1024 * 16]).await;
|
||||
};
|
||||
f.await
|
||||
}
|
||||
async fn calls_fut(fut: impl std::future::Future<Output = ()>) {
|
||||
loop {
|
||||
wait().await;
|
||||
if true {
|
||||
return fut.await;
|
||||
} else {
|
||||
wait().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test() {
|
||||
let fut = big_fut([0u8; 1024 * 16]);
|
||||
foo().await;
|
||||
calls_fut(fut).await;
|
||||
}
|
||||
|
||||
pub fn foo() -> impl std::future::Future<Output = ()> {
|
||||
async {
|
||||
let x = [0i32; 1024 * 16];
|
||||
async {}.await;
|
||||
dbg!(x);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
40
tests/ui/large_futures.stderr
Normal file
40
tests/ui/large_futures.stderr
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
error: large future with a size of 16385 bytes
|
||||
--> $DIR/large_futures.rs:12:9
|
||||
|
|
||||
LL | big_fut([0u8; 1024 * 16]).await;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))`
|
||||
|
|
||||
= note: `-D clippy::large-futures` implied by `-D warnings`
|
||||
|
||||
error: large future with a size of 16386 bytes
|
||||
--> $DIR/large_futures.rs:14:5
|
||||
|
|
||||
LL | f.await
|
||||
| ^ help: consider `Box::pin` on it: `Box::pin(f)`
|
||||
|
||||
error: large future with a size of 16387 bytes
|
||||
--> $DIR/large_futures.rs:18:9
|
||||
|
|
||||
LL | wait().await;
|
||||
| ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())`
|
||||
|
||||
error: large future with a size of 16387 bytes
|
||||
--> $DIR/large_futures.rs:22:13
|
||||
|
|
||||
LL | wait().await;
|
||||
| ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())`
|
||||
|
||||
error: large future with a size of 65540 bytes
|
||||
--> $DIR/large_futures.rs:29:5
|
||||
|
|
||||
LL | foo().await;
|
||||
| ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())`
|
||||
|
||||
error: large future with a size of 49159 bytes
|
||||
--> $DIR/large_futures.rs:30:5
|
||||
|
|
||||
LL | calls_fut(fut).await;
|
||||
| ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue