-
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
Rework suggestion generation of unit_arg
lint
#4455
Conversation
Building a well formatted suggestion is nearly impossible (at least I don't know how to do it), so this part has to be done by a If the expression that got moved out of the function call has no effect, the |
Well multipart suggestions are not autofixable, with more than one suggestion rust-lang/rustfix#162, rust-lang/rust#53934 Let's try something else. |
f8433f0
to
3e7121a
Compare
unit_arg
lintunit_arg
lint
Well that for every arg the help message is displayed once is not optimal. But it is still an improvement to before, where for every arg the lint message was emitted once. |
3e7121a
to
c78f1dc
Compare
On rewriting the suggestion of this lint, I realized a few things:
Thoughts? |
☔ The latest upstream changes (presumably #4739) made this pull request unmergeable. Please resolve the merge conflicts. |
0d5f4f4
to
28863cd
Compare
☔ The latest upstream changes (presumably #4962) made this pull request unmergeable. Please resolve the merge conflicts. |
28863cd
to
3cc17f0
Compare
Correct me if I am wrong, the only context where you reasonably have a
is much better from the "understanding what's going on" standpoint. When I see |
I think we can make this |
I can easily see someone calling a log function with an extra semicolon in a block argument. I wouldn't want rustfix to silently move it out, I would rather leave it as a warning for a programmer to deal with. |
Hm, good point. But if that would be the case it would've logged What do you think of a second suggestion to remove the semicolon from the last statement in a block, in addition to moving the block out? That way, this wouldn't be applied by rustfix, since there are 2 different suggestions. |
That sounds good if that is how rustfix works. So in case you have more than one suggestion (even if only one of them is machine applicable), it does nothing? |
Yeah, since rustfix won't decide which suggestion to apply, if multiple fixes are possible. |
3cc17f0
to
d86472d
Compare
5eba680
to
5924fa6
Compare
☔ The latest upstream changes (presumably #5257) made this pull request unmergeable. Please resolve the merge conflicts. |
tests/ui/unit_arg.stderr
Outdated
LL | foo({}); | ||
| ^^ | ||
| ^^^^^^^ | ||
| | ||
= note: `-D clippy::unit-arg` implied by `-D warnings` | ||
help: if you intended to pass a unit value, use a unit literal instead | ||
help: move the expression in front of the call... | ||
| | ||
LL | {}; |
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.
Hmm, so the {}
is an expression (a block) that returns ()
? Shouldn't the lint still provide the old suggestion here, instead of the two new ones? I don't think there's any point in moving an empty block expression out of the function args?
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.
This would be handled by the no_effect
lint afterwards I think. But special casing empty blocks would definitely make sense here. I'll add this to the suggestion generation.
@bors treeclosed- |
multipart suggestions aren't autofixable by rustfix yet
LGTM! @bors r+ |
📌 Commit 77dd0ea has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Found this bug while running
cargo fix --clippy
on quite a big codebase:This would replace something like:
with
which obviously suppresses side effects.
Since pretty much every expression could have side effects, I think making this suggestion
MaybeIncorrect
is the best thing to do here.A correct suggestion would be:
Somehow the suggestion is not correctly applied to the arguments, when more than one argument is a unit value. I have to look into this a little more, though.
changelog: Fixes suggestion of
unit_arg
lint, so that it suggests semantic equivalent codeFixes #4741