blob: bd1b31f74ee957c17afe4baa9750a1b20e0f0631 [file] [log] [blame] [edit]
#![warn(clippy::async_yields_async)]
#![allow(clippy::redundant_async_block)]
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
}
async fn f() -> CustomFutureType {
// Don't warn for functions since you have to explicitly declare their
// return types.
CustomFutureType
}
#[rustfmt::skip]
fn main() {
let _f = {
3
};
let _g = async {
3
};
let _h = async {
async {
3
}.await
};
//~^^^^ async_yields_async
let _i = async {
CustomFutureType.await
};
//~^^ async_yields_async
let _i = async || {
3
};
let _j = async || {
async {
3
}.await
};
//~^^^^ async_yields_async
let _k = async || {
CustomFutureType.await
};
//~^^ async_yields_async
let _l = async || CustomFutureType.await;
//~^ async_yields_async
let _m = async || {
println!("I'm bored");
// Some more stuff
// Finally something to await
CustomFutureType.await
};
//~^^ async_yields_async
let _n = async || custom_future_type_ctor();
let _o = async || f();
}
#[rustfmt::skip]
#[allow(dead_code)]
fn check_expect_suppression() {
#[expect(clippy::async_yields_async)]
let _j = async || {
async {
3
}
};
}
#[allow(clippy::let_underscore_future)]
fn issue15552() {
async fn bar(i: i32) {}
macro_rules! call_bar {
() => {
async { bar(5).await }
};
($e:expr) => {
bar($e)
};
}
let x = async { call_bar!(5).await };
//~^ async_yields_async
let y = async { call_bar!().await };
//~^ async_yields_async
//~| async_yields_async
use std::future::{Future, Ready};
use std::ops::Add;
use std::pin::Pin;
use std::task::{Context, Poll};
struct CustomFutureType;
impl Add for CustomFutureType {
type Output = Self;
fn add(self, other: Self) -> Self {
self
}
}
impl Future for CustomFutureType {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(())
}
}
let _ = async { (CustomFutureType + CustomFutureType).await };
//~^ async_yields_async
}