Skip to content

wrong: warning: unneeded return statement #13457

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

Closed
eareimu opened this issue Sep 26, 2024 · 0 comments · Fixed by #13464
Closed

wrong: warning: unneeded return statement #13457

eareimu opened this issue Sep 26, 2024 · 0 comments · Fixed by #13464
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@eareimu
Copy link

eareimu commented Sep 26, 2024

Summary

Wrong message

Reproducer

While im writing the document for https://github.com/genmeta/gm-quic/blob/main/qbase/src/util/future.rs#L206, the clippy reporeted a wrong message.

I expected to see this happen:

No warn.

Instead, this happened:

Image

Version

rustc 1.83.0-nightly (9e394f551 2024-09-25)
binary: rustc
commit-hash: 9e394f551c050ff03c6fc57f190e0761cf0be6e8
commit-date: 2024-09-25
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

Additional Labels

No response

@eareimu eareimu added the C-bug Category: Clippy is not doing the correct thing label Sep 26, 2024
@bors bors closed this as completed in 8e60f14 Oct 10, 2024
eareimu added a commit to genmeta/gm-quic that referenced this issue Oct 16, 2024
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant