-
Notifications
You must be signed in to change notification settings - Fork 1.6k
'unneeded return' fires when return is needed due to attribute #9361
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
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
bors
added a commit
that referenced
this issue
Aug 27, 2022
Don't lint `needless_return` if `return` has attrs Fixes #9361 The lint used to have a mechanic to allow `cfg`-attrs on naked `return`-statements. This was well-intentioned, yet we can have any kind of attribute, e.g. `allow`, `expect` or even custom `derive`. So the mechanic was simply removed. We now never lint on a naked `return`-statement that has attributes on it. Turns out that the ui-test had a Catch22 in it: In `check_expect()` the `#[expect(clippy::needless_return)]` is an attribute on the `return` statement that can and will be rustfixed away without side effects. But any other attribute would also have been removed, which is what #9361 is about. The test proved the wrong thing. Removed the test, the body is tested elsewhere as well.
bors
added a commit
that referenced
this issue
Aug 27, 2022
Don't lint `needless_return` if `return` has attrs Fixes #9361 The lint used to have a mechanic to allow `cfg`-attrs on naked `return`-statements. This was well-intentioned, yet we can have any kind of attribute, e.g. `allow`, `expect` or even custom `derive`. So the mechanic was simply removed. We now never lint on a naked `return`-statement that has attributes on it. Turns out that the ui-test had a Catch22 in it: In `check_expect()` the `#[expect(clippy::needless_return)]` is an attribute on the `return` statement that can and will be rustfixed away without side effects. But any other attribute would also have been removed, which is what #9361 is about. The test proved the wrong thing. Removed the test, the body is tested elsewhere as well. changelog: Ignore [`needless_return`] on `return`s with attrs
This was referenced Jun 30, 2024
bors
added a commit
that referenced
this issue
Jul 3, 2024
`needless_return`: Support `#[expect]` on the return statement A fix for #9361 suppresses `clippy::needless_return` if there are any attributes on the `return` statement. This leads to some unexpected behavior, as described in #12998, where adding `#[expect(clippy::needless_return)]` suppresses the lint, but doesn't fulfill the expectation. I now decided to manually fulfill any expectations, if they are before the attribute check. --- Closes: #12998 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
Description
Consider code like this:
The
return
is needed here because attributes can only be applied to statements, not expressions. But nevertheless clippy says I should remove thereturn
...Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: