Skip to content

Commit

Permalink
Add regression test for issue 236
Browse files Browse the repository at this point in the history
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
         |
  • Loading branch information
dtolnay committed Jan 30, 2023
1 parent 36bcff4 commit e6e736f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,3 +1556,31 @@ pub mod issue234 {
async fn f(Tuple { 1: _int, .. }: Tuple<Droppable, i32>) {}
}
}

// 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<Output = Ready<()>> {
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(())
}
}
}

0 comments on commit e6e736f

Please sign in to comment.