Skip to content

redundant_async_block creates invalid code in async tests #10525

@teor2345

Description

@teor2345

Summary

cargo clippy --fix creates async functions without braces when I run it on my test code.

I don't know if it's the tokio::test macro, or the returned Result that's causing the bug.

Reproducer

I tried this code:

#[tokio::test(flavor = "multi_thread")]
async fn single_item_checkpoint_list_test() -> Result<(), Report> {
    single_item_checkpoint_list().await
}

#[spandoc::spandoc]
async fn single_item_checkpoint_list() -> Result<(), Report> {
    ...
}

I expected to see this happen:

Fix with correct code.

Instead, this happened:

I got this code without braces:

async fn single_item_checkpoint_list_test() -> Result<(), Report> single_item_checkpoint_list()

...

And when I tried a manual fix:

async fn single_item_checkpoint_list_test() -> Result<(), Report> {
    single_item_checkpoint_list()
}

I got this error:

error[E0308]: mismatched types
     |                                          ---------- expected `std::result::Result<(), ErrReport>` because of return type
     |     ^^^^^^^^^^^^^^^^^^^ expected `Result<(), Report>`, found future
note: calling an async function returns a future
help: consider `await`ing on the `Future`

So I think this is also a false positive, due to a macro on the function.

Version

rustc 1.70.0-nightly (44f518058 2023-03-20)
binary: rustc
commit-hash: 44f5180584404d18058cbbf224c55255db4fdcbb
commit-date: 2023-03-20
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions