-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add new lint to warn when #[must_use] attribute should be used on a method #8071
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
eb71297
to
8f03d3d
Compare
hir_id: HirId, | ||
) { | ||
if_chain! { | ||
// We are only interested in methods, not in functions or associated functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? What about fn new() -> Self
, fn new_foo(bar: Baz) -> Self
or fn from_blurb(blurb: Blurb) -> Self
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They look like different use cases to me. What I'm trying to prevent here is cases like 0f32.rad(2.)
. It's much less likely (in my opinion) if it's not a method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sure, if you don't want to cover that case here that makes sense. I also think it's quite unlikely that someone calls such a constructor function and forgets to actually do something with the result. Adding #[must_use]
on all these might add quite a bit of noise to the code.
8f03d3d
to
f305926
Compare
Updated with @sdroege's suggestions. |
I'd call it For the category I'd do |
ca04751
to
aecc38d
Compare
@camsteffen This is indeed much better, I renamed the lint. |
aecc38d
to
63b6787
Compare
And updated the category to pedantic. |
63b6787
to
56d2ab3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation logic looks good to me. There are some minor improvements to be made, and then it should be ready to be merged. 👍
Also, a thank you to the ones who have given feedback already. I appreciate it! 🙃
56d2ab3
to
037d52e
Compare
037d52e
to
e93767b
Compare
Updated with comments from @xFrednet. :) |
Everything looks good to me, thank you for the work! I ran the lint on 25 crates with lintcheck and got about 60 reports, the once I've looked at seem to be correct. 🙃 @bors r+ |
📌 Commit e93767b has been approved by |
Add new lint to warn when #[must_use] attribute should be used on a method This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions). Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312 I think it would reduce the number of cases of API misuses quite a lot. What do you think?
💔 Test failed - checks-action_test |
Clippy created the changelog based on the PR description. I added the corresponding message 🙃 @bors r+ |
Add new lint to warn when #[must_use] attribute should be used on a method This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions). Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312 I think it would reduce the number of cases of API misuses quite a lot. What do you think? --- changelog: Added new [`return_self_not_must_use`] lint
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Thanks! |
This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).
Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312
I think it would reduce the number of cases of API misuses quite a lot.
What do you think?
changelog: Added new [
return_self_not_must_use
] lint