-
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
fix incorrect suggestion for !(a >= b) as i32 == c
#13338
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Centri3 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
fd516a0
to
9dce27c
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.
I'd say we should use Sugg::maybe_par
in clippy_utils
for this. The code is correct for this case, but it's missing other cases (mostly binary ops) where parentheses are required. For example, !(1 >= 2) | true == a
also causes the same issue, which the suggested function handles.
9dce27c
to
41f79f7
Compare
I wasn't familiar with the |
41f79f7
to
bc63bd2
Compare
Given the fact that |
☔ The latest upstream changes (presumably #13443) made this pull request unmergeable. Please resolve the merge conflicts. |
Well, this code is incorrect when the suggestion is applied: fn a(a: bool) -> bool {
(!(4 > 3)).b()
}
trait B {
fn b(&self) -> bool { true }
}
impl B for bool {} Really, is there any reason not to use |
bc63bd2
to
ebfa809
Compare
Using
|
846980e
to
06ecdf4
Compare
|
Yes, I know, this is a non-issue as Why do we need the parent expression? Is there any case where it misses required parentheses in that case? This feels overly complicated for 2 characters that will likely be removed on the next clippy run. |
06ecdf4
to
0e2f9fc
Compare
Deleted the parent expression stuff. |
0e2f9fc
to
d30a026
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.
Thanks 👍
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #12761
The expression
!(a >= b) as i32 == c
got simplified toa < b as i32 == c
, but this is a syntax error.The result we want is
(a < b) as i32 == c
.This is fixed by adding a parenthesis to the suggestion given in
check_simplify_not
when the boolean expression is casted.changelog: [
nonminimal_bool
]: fix incorrect suggestion for!(a >= b) as i32 == c