-
Notifications
You must be signed in to change notification settings - Fork 1.6k
needless_return
: Support #[expect]
on the return statement
#13027
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
Conversation
This does mean something like: fn f() -> i32 {
#[expect(clippy::needless_return)]
#[some_other_attribute]
return 1;
} will fulfill the expectation even though it technically shouldn't. I don't think this is a problem in practice, but it can be fixed by checking if the only attribute on the statement is |
I considered parsing the attributes again, just checking for the attribute, might not be enough, since the expectation could also come from a higher level. It would basically end up parsing the entire all attributes again, to see if they are specific to this case. I could do that, but it felt like unnecessary complexity. Do you think I should do that? |
What's a "higher level" referring to here? Do you mean a lint group or something higher in the AST? |
With higher level, I meant in the AST. Sorry for not clarifying this. However, the group is also a good example that I didn't consider. I was thinking of this #[expect(needless_return)]
fn ex() {
#[expect(lint_a)]
return n;
} This would have the expect lint level for |
If it's higher in the AST then it should be unfulfilled. This is a variation on my original point. Since fn ex() {
#[expect(lint_a)]
return n;
} Adding For the case of lint groups I would want to disallow It's easy enough to work around anyways. If the return has either no attributes; or a single attribute which is |
dd17d6e
to
588a04f
Compare
I believe I've now implemented your suggestion, where I check if there is only one attribute and that expects the either |
588a04f
to
d29b330
Compare
Can you add a comment next to the lint category mentioning that any changes to the category need to change the implementation as well? The test should catch this, but it's nicer to be warned up front about it. |
I have the feeling
And the expectation is always fulfilled, no matter what I do. But I've added it now as a test and to the code as well. |
d29b330
to
903874d
Compare
I guess I should've played with it more. Oh well. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
A fix for #9361 suppresses
clippy::needless_return
if there are any attributes on thereturn
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