-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Detect underscored variables with no side effects #7775
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
This lint should be allowed in all test cases, that don't explicitly test for this lint. Otherwise all the stderr files are just messy. Please also add a test case, where the assigned value implements I'm also not so sure if this should be an extension of the let _x = 42; // only required if *one of* f1 or f2 is enabled,
// but has to be declared with `_` to avoid warning if none of those features are enabled
let mut y = 0;
// If feature 1 is enabled call foo with `_x - 1`
#[cfg(feature = "f1")]
{ y += foo(_x - 1); }
// If feature 2 is enabled call foo with `_x + 1`
#[cfg(feature = "f2")]
{ y += foo(_x + 1); }
y += foo(0); |
@flip1995 I had issues with What would be potential issue with Functionality wise, it makes sense to make this part of the I think this makes most sense if used with existing |
Yes exactly:
Agreed. It's easy to just define another lint and pass it to the
There are two problems with this though.
|
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.
I'm also in favor of having this in a new lint, as discussed above, and maybe having it allow-by-default. The logic still looks good, just two NITs and there are still some .stderr
with lint triggers where no_effect
or the new lint should be allowed in 🙃
74b4b83
to
ef24685
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.
Having a new lint for values starting with underscores seems good to me. Thank you for the refactoring 🙃
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 part looks good to me. This should be ready for merge once the test output has been added. I also used lintcheck and everything is looking good. You can also squash some commits if you want 🙃
Fix tests after no_effect update Add a drop testcase Don't lint _ variables in macro expansion Address review comments and update tests Don't shadow unnecessary operation lint if no_effect is allowed Revert shadowing change and remove no_effect allows Update clippy_lints/src/no_effect.rs Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com> Update clippy_lints/src/no_effect.rs Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com> Address review comments
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.
LGTM! Thank you for the work and refactoring the code several times! 🙃
@bors r+ |
📌 Commit 6b22bba has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
@xFrednet np, thanks for reviews 😄 |
Fixes #7545
changelog: Lint on underscored variables with no side effects in [
no_effect
]