Closed
Description
Summary
Functions with the async
keyword get the following error, even when the functions must have async to be used in contexts that are async.
unused `async` for function with no await statements
Lint Name
unused_async
Reproducer
I tried this code:
[package]
name = "pro"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = { version = "0.5" }
tokio = { version = "1.0", features = ["full"] }
use axum::{routing::get, Router};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let router = Router::new().route("/", get(home));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
axum::Server::bind(&addr)
.serve(router.into_make_service())
.await
.unwrap();
}
async fn home() -> &'static str {
"Hello, World!"
}
I expected to see this happen:
No warnings.
Instead, this happened:
warning: unused `async` for function with no await statements
--> src/main.rs:15:1
|
15 | / async fn home() -> &'static str {
16 | | "Hello, World!"
17 | | }
| |_^
|
= note: `-W clippy::unused-async` implied by `-W clippy::pedantic`
= help: consider removing the `async` from this function
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
Version
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-apple-darwin
release: 1.64.0
LLVM version: 14.0.6