From e6e736f8df5343eab9e966cedb3e2e2bd407690d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 Jan 2023 12:59:08 -0800 Subject: [PATCH 1/2] Add regression test for issue 236 Currently fails: error: an async construct yields a type which is itself awaitable --> tests/test.rs:1582:35 | 1582 | async fn f() -> Ready<()> { | ___________________________________^ 1583 | | future::ready(()) 1584 | | } | | ^ | | | | |_________outer async construct | awaitable value not awaited | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async note: the lint level is defined here --> tests/test.rs:1562:13 | 1562 | #![deny(clippy::async_yields_async)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider awaiting this value | 1582 ~ async fn f() -> Ready<()> { 1583 + future::ready(()) 1584 + }.await | --- tests/test.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 2d7dc65..458904e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1556,3 +1556,31 @@ pub mod issue234 { async fn f(Tuple { 1: _int, .. }: Tuple) {} } } + +// https://github.com/dtolnay/async-trait/issues/236 +pub mod issue236 { + #![deny(clippy::async_yields_async)] + #![allow(clippy::manual_async_fn)] + + use async_trait::async_trait; + use std::future::{self, Future, Ready}; + + // Does not trigger the lint. + pub async fn async_fn() -> Ready<()> { + future::ready(()) + } + + #[allow(clippy::async_yields_async)] + pub fn impl_future_fn() -> impl Future> { + async { future::ready(()) } + } + + // The async_trait attribute turns the former into the latter, so we make it + // put its own allow(async_yeilds_async) to remain consistent with async fn. + #[async_trait] + pub trait Trait { + async fn f() -> Ready<()> { + future::ready(()) + } + } +} From 54cc1ce43870e3de36f12d197ff0663a1e2e8b40 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 30 Jan 2023 13:00:28 -0800 Subject: [PATCH 2/2] Suppress async_yields_async clippy correctness lint in generated code --- src/expand.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/expand.rs b/src/expand.rs index c2cfacb..88338db 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -119,6 +119,7 @@ pub fn expand(input: &mut Item, is_local: bool) { fn lint_suppress_with_body() -> Attribute { parse_quote! { #[allow( + clippy::async_yields_async, clippy::let_unit_value, clippy::no_effect_underscore_binding, clippy::shadow_same,