-
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
Ban Stacked if
's
#12483
Comments
I don't think it should be limited to if if a == b {
"a"
} else {
"b"
} == "a" {
"c"
} else {
"d"
} But a partial solution is still helpful. |
I hadn't considered that, and I agree, it looks horrible. Perhaps if clippy ever sees |
This comes up occasionally. We'd probably want to suggest extracting it to a variable even though it won't be reached very often. (Also note that we don't have to entirely clean up in one run - just peeling one layer at a time is okay.) Note that Beware drop temps - check for |
Oh also, blocks in the condition of an |
@Centri3 I would greatly prefer that In particular, my understanding is lints, including clippy lints, also fire on macro-generated code after all, and macros have to use lots of blocks and Returning to the main subject, |
I was thinking of longer blocks, not single expressions. Pedantic was what I was thinking. Macros aren't a worry and we usually don't lint in them (unless it's a logic bug/UB) |
I was going to ask "is this something that could realistically happen in the wild?". A cursory search for |
@rustbot claim |
perhaps there should be a configurable maximum level, i don't think single stacked ifs are too hard to read if you format them like a ternary. |
@rustbot claim |
What it does
This lint should prohibit placing
bool
returningif
statements as the expression inside anotherif
statement. Currently, there appears to be no limit to the depth of stackedif
's permitted by bothrust fmt
andclippy
Advantage
if
's are hard to readDrawbacks
if
statement, but I personally think that's poor formExample
Could be written as:
The text was updated successfully, but these errors were encountered: