-
Notifications
You must be signed in to change notification settings - Fork 1.7k
handle another type of collapsible if-statement #15104
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
base: master
Are you sure you want to change the base?
Conversation
This PR is an updated version of PR #15027. |
… previous commit. Correct specifying of applicability for calls to functions that modify an `Applicability`. Update suggestion message to adhere to standard conventions. Change default value passed to `Sugg::hir_with_applicability` to a suitable one. Format code. Update the corresponding `stderr` file for this lint.
@samueltardieu Thanks for the review, I have implemented your suggested changes in my latest commit and was wondering if you could re-review it? |
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 suggestion may be wrong when operators other than ==
or !=
are used. Please fix, and also add more complicated tests involving conditions with binary operators, including &&
and ||
operators.
let new_bin_op = if let BinOpKind::Ne = bin_op.node { | ||
BinOpKind::Eq | ||
} else { | ||
BinOpKind::Ne | ||
}; |
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.
What about other binary operations? Right now, the following
let a = 10;
let b = 20;
if a < 20 {
if b < 30 {
println!("Hello");
}
} else {
println!("world!");
}
will be transformed into the (non equivalent)
if a != 20 || b < 30 {
println!("Hello world!");
}
You should look at the !
operator for Sugg
and let it invert the operation, it might be beneficial.
Thanks for the review, I'll work on implementing those suggestions. |
fixes #812
changelog: [
collapsible_if
]: handle another type of collapsible if-statement