-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Kickstart the usage of let_chains
#8360
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
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 just though about doing this today 😄
This is great. With more of this, we should be able to get rid of if_chain!
completely, right?
} | ||
if attr.has_name(sym::cfg) | ||
&& let Some(list) = attr.meta_item_list() | ||
&& let mismatched = find_mismatched_target_os(&list) |
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.
Oh nice, you can even put irrefutable patterns in let chains 👍
} | ||
if let Some(parent) = get_parent_expr(self.cx, expr) | ||
&& let ExprKind::MethodCall(_, [self_arg, ..], _) = &parent.kind | ||
&&let caller = self.cx.typeck_results().expr_ty(self_arg) |
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.
&&let caller = self.cx.typeck_results().expr_ty(self_arg) | |
&& let caller = self.cx.typeck_results().expr_ty(self_arg) |
Formatting. Is rustfmt
not able to format let chains yet?
This is the one major issue I have with if_chain!
– code inside of it isn't automatically formatted.
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.
Not yet -> rust-lang/rustfmt#5177
I guess it will be tackled eventually
Probably yes but also serves to battle-test the feature |
There's probably no better place to test this than Clippy. It's |
check_semver(cx, item.span(), lit); | ||
} | ||
} | ||
if let Some(items) = &attr.meta_item_list() && let Some(ident) = attr.ident() { |
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 think && let
should always wrap to the next line. Does rustfmt allow either way?
I'm gonna miss our dear friend |
Closing due to formatting concerns. If desired, feel free to use any content of this PR for posterior submissions |
I guess it makes sense to wait for rustfmt support? We already don't have formatting in |
I also think we can accept PRs beforehand. As you said, |
I was mainly giving reasons to not migrate yet. But I don't have a strong opinion. |
Sorry, in that case I misunderstood you 😅. I thought it would be good to merge one PR like this one, to test the feature and to make sure that it work for us. Formatting is less important for a test. We can see if this causes any regressions in Nightly and there would still be time to fix it. However, I also don't have a strong opinion on this either xD |
I guess we could merge a PR like this. But it doesn't give any benefit for Clippy until it can be automatically formatted. If we merge a PR like this, I would first limit it to |
In any case, I got the ball rolling for rustfmt support! rust-lang/rustfmt#5203 |
Format `if_chain` invocations in clippy_utils Not realizing it was [already obsolete](#8360), I built a [tool to format inside `if_chain` invocations](https://crates.io/crates/rustfmt_if_chain). This PR applies the tool to clippy_utils. (If you apply it to clippy_lints, the changes are extensive.) Anyway, I'm making it known here in case anyone wants to use it while `if-let` chain support is developed for `rustfmt`. (There could be a few Clippy PRs between now and then, and IMHO, the code looks better with the `if_chain` invocations formatted.) Cheers.
Format `if_chain` invocations in clippy_utils Not realizing it was [already obsolete](#8360), I built a [tool to format inside `if_chain` invocations](https://crates.io/crates/rustfmt_if_chain). This PR applies the tool to clippy_utils. (If you apply it to clippy_lints, the changes are extensive.) Anyway, I'm making it known here in case anyone wants to use it while `if-let` chain support is developed for `rustfmt`. (There could be a few Clippy PRs between now and then, and IMHO, the code looks better with the `if_chain` invocations formatted.) Cheers. --- changelog: none
The time has come