rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.47k stars 1.55k forks source link

Incorrect clippy::needless_return on async tests in latest nightly #13458

Closed amircodota closed 1 month ago

amircodota commented 1 month ago

Summary

In the latest nightly, on tokio::test functions, the last assert is flagged with clippy::needless_return

Reproducer

I tried this code:

#[tokio::test]
async fn test1() {
    assert_eq!(4, 5);
}

And ran this

cargo +nightly clippy --all-targets --all-features 

I expected to see this happen:

I expected clippy to pass

Instead, this happened:

It write this error

warning: unneeded `return` statement
 --> src/main.rs:7:21
  |
7 |     assert_eq!(4, 5);
  |                     ^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
  = note: `#[warn(clippy::needless_return)]` on by default

Version

rustc 1.83.0-nightly (9e394f551 2024-09-25) binary: rustc commit-hash: 9e394f551c050ff03c6fc57f190e0761cf0be6e8 commit-date: 2024-09-25 host: x86_64-unknown-linux-gnu release: 1.83.0-nightly LLVM version: 19.1.0

Additional Labels

No response

ia0 commented 1 month ago

Same issue with tokio::main.

use anyhow::Result;

#[tokio::main]
async fn main() -> Result<()> {
    Ok(())
}
warning: unneeded `return` statement
 --> src/main.rs:5:7
  |
5 |     Ok(())
  |       ^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
  = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
  |
5 |     OkOk(())
  |       ~~~~~~

warning: `foo` (bin "foo") generated 1 warning (run `cargo clippy --fix --bin "foo"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
cyqsimon commented 1 month ago
help: remove `return`
  |
5 |     OkOk(())
  |       ~~~~~~

Clippy is drunk 🍺