2021-05-20 10:30:31 +00:00
|
|
|
#![warn(clippy::unused_async)]
|
2023-07-02 12:35:19 +00:00
|
|
|
#![allow(incomplete_features)]
|
2021-05-20 10:30:31 +00:00
|
|
|
|
2022-06-30 08:50:09 +00:00
|
|
|
use std::future::Future;
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
2023-06-02 09:41:57 +00:00
|
|
|
mod issue10800 {
|
|
|
|
#![allow(dead_code, unused_must_use, clippy::no_effect)]
|
|
|
|
|
|
|
|
use std::future::ready;
|
|
|
|
|
|
|
|
async fn async_block_await() {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: unused `async` for function with no await statements
|
2023-06-02 09:41:57 +00:00
|
|
|
async {
|
|
|
|
ready(()).await;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn normal_block_await() {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ready(()).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 12:35:19 +00:00
|
|
|
mod issue10459 {
|
|
|
|
trait HasAsyncMethod {
|
|
|
|
async fn do_something() -> u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasAsyncMethod for () {
|
|
|
|
async fn do_something() -> u32 {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 21:53:53 +00:00
|
|
|
mod issue9695 {
|
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
async fn f() {}
|
|
|
|
async fn f2() {}
|
|
|
|
async fn f3() {}
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: unused `async` for function with no await statements
|
2023-07-31 21:53:53 +00:00
|
|
|
|
|
|
|
fn needs_async_fn<F: Future<Output = ()>>(_: fn() -> F) {}
|
|
|
|
|
|
|
|
fn test() {
|
|
|
|
let x = f;
|
|
|
|
needs_async_fn(x); // async needed in f
|
|
|
|
needs_async_fn(f2); // async needed in f2
|
|
|
|
f3(); // async not needed in f3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 21:38:38 +00:00
|
|
|
mod issue13466 {
|
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
struct Wrap<F>(F);
|
|
|
|
impl<F> From<F> for Wrap<F> {
|
|
|
|
fn from(f: F) -> Self {
|
|
|
|
Self(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn takes_fut<F: Fn() -> Fut, Fut: Future>(_: Wrap<F>) {}
|
|
|
|
async fn unused_async() {}
|
|
|
|
fn fp() {
|
|
|
|
takes_fut(unused_async.into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:30:31 +00:00
|
|
|
async fn foo() -> i32 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: unused `async` for function with no await statements
|
2021-05-20 10:30:31 +00:00
|
|
|
4
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn bar() -> i32 {
|
|
|
|
foo().await
|
|
|
|
}
|
|
|
|
|
2022-06-30 08:50:09 +00:00
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl S {
|
|
|
|
async fn unused(&self) -> i32 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: unused `async` for function with no await statements
|
2022-06-30 08:50:09 +00:00
|
|
|
1
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn used(&self) -> i32 {
|
|
|
|
self.unused().await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait AsyncTrait {
|
|
|
|
fn trait_method() -> Pin<Box<dyn Future<Output = i32>>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! async_trait_impl {
|
|
|
|
() => {
|
|
|
|
impl AsyncTrait for S {
|
|
|
|
fn trait_method() -> Pin<Box<dyn Future<Output = i32>>> {
|
|
|
|
async fn unused() -> i32 {
|
|
|
|
5
|
|
|
|
}
|
|
|
|
|
|
|
|
Box::pin(unused())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
async_trait_impl!();
|
|
|
|
|
2021-05-20 10:30:31 +00:00
|
|
|
fn main() {
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
}
|