rust-clippy/tests/ui/async_yields_async.rs
Kyle Huey 4972989b61 Add a lint for an async block/closure that yields a type that is itself awaitable.
This catches bugs of the form

tokio::spawn(async move {
    let f = some_async_thing();
    f // Oh no I forgot to await f so that work will never complete.
});
2020-08-29 15:33:54 -07:00

61 lines
1 KiB
Rust

// run-rustfix
// edition:2018
#![feature(async_closure)]
#![warn(clippy::async_yields_async)]
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};
struct CustomFutureType;
impl Future for CustomFutureType {
type Output = u8;
fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll<Self::Output> {
Poll::Ready(3)
}
}
fn custom_future_type_ctor() -> CustomFutureType {
CustomFutureType
}
#[rustfmt::skip]
fn main() {
let _f = {
3
};
let _g = async {
3
};
let _h = async {
async {
3
}
};
let _i = async {
CustomFutureType
};
let _i = async || {
3
};
let _j = async || {
async {
3
}
};
let _k = async || {
CustomFutureType
};
let _l = async || CustomFutureType;
let _m = async || {
println!("I'm bored");
// Some more stuff
// Finally something to await
CustomFutureType
};
let _n = async || custom_future_type_ctor();
}