Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amircodota opened this issue Sep 26, 2024 · 2 comments · Fixed by #13464
Closed

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

amircodota opened this issue Sep 26, 2024 · 2 comments · Fixed by #13464
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@amircodota
Copy link

amircodota commented Sep 26, 2024

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

@amircodota amircodota added the C-bug Category: Clippy is not doing the correct thing label Sep 26, 2024
@ia0
Copy link

ia0 commented Sep 26, 2024

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

@y21 y21 added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Sep 26, 2024
@cyqsimon
Copy link

cyqsimon commented Oct 1, 2024

help: remove `return`
  |
5 |     OkOk(())
  |       ~~~~~~

Clippy is drunk 🍺

avrabe added a commit to avrabe/fmu-rs that referenced this issue Oct 5, 2024
The allowed one is related to rust-lang/rust-clippy#13458 as we start as tokio::main and never return.
avrabe added a commit to avrabe/fmu-rs that referenced this issue Oct 5, 2024
The allowed one is related to rust-lang/rust-clippy#13458 as we start as tokio::main and never return.
AlexTMjugador added a commit to ComunidadAylas/PackSquash that referenced this issue Oct 6, 2024
Our problem was already reported and is being tracked upstream at
rust-lang/rust-clippy#13458.
appcypher added a commit to appcypher/monocore that referenced this issue Oct 7, 2024
* fix: downloaded layer integrity checks

- checking that file has already been downloaded
- check file integrity after download
- change directory where layers are downloaded to no include registry like `docker` subdir

* chore: disabling nightly checks because clippy nightly is buggy

- see rust-lang/rust-clippy#13458
Celeo added a commit to Celeo/vzdv that referenced this issue Oct 8, 2024
@bors bors closed this as completed in 8e60f14 Oct 10, 2024
will-lynas added a commit to will-lynas/quaestor that referenced this issue Oct 11, 2024
ia0 added a commit to ia0/magika that referenced this issue Oct 18, 2024
It was disabled by google#726 due to a false positive tracked and fixed by rust-lang/rust-clippy#13458.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Oct 18, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants