-
Notifications
You must be signed in to change notification settings - Fork 13.3k
style guide: add let-chain rules #139456
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
style guide: add let-chain rules #139456
Conversation
rustbot has assigned @joshtriplett. Use |
Some changes occurred in src/doc/style-guide cc @rust-lang/style |
&& let Some(relatively_long_thing) = | ||
a_long_long_long_long_long_long_really_reallllllllllyyyyyyy_long_expression |
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.
Shouldn't the =
be on the second line here, given the explanation above of "prefer to break before the =
"?
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.
Good catch
I think the "before operator" prescription may have been a snippet of text we missed in #113145 (and some more context linked in rust-lang/style-team#179) when we changed the text to match the existing behavior of always breaking after the operator
for example, rustfmt has long formatted chainless if let Some(....) ....
with breaks after =
- https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=9f656a763b2b09c559d39568c2d5079c
fn main() {
if let Some(x) = a_long_long_long_long_long_long_really_realllyyyy_long_expressionddddddddddddddddd {
// ..
}
if let Some(relatively_long_thing) =
a_long_long_long_long_long_long_really_realllyyyy_long_expression
{
// ..
}
}
is formatted as:
fn main() {
if let Some(x) =
a_long_long_long_long_long_long_really_realllyyyy_long_expressionddddddddddddddddd
{
// ..
}
if let Some(relatively_long_thing) =
a_long_long_long_long_long_long_really_realllyyyy_long_expression
{
// ..
}
}
I'm going to change the text in the control flow section to indicate breaking after under the same rationale as we had previously of "bug fix" to the style guide text, but happy to discuss more if you think that's the wrong direction
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.
Good call. I agree that we should match the existing behavior.
@calebcartwright One review comment; with that addressed, r=me. |
b7080a1
to
ee07e3f
Compare
LGTM, r=me whenever you think it ready. |
@bors r=joshtriplett rollup |
Rollup of 5 pull requests Successful merges: - rust-lang#138314 (fix usage of `autodiff` macro with inner functions) - rust-lang#139426 (Make the UnifyKey and UnifyValue imports non-nightly) - rust-lang#139431 (Remove LLVM 18 inline ASM span fallback) - rust-lang#139456 (style guide: add let-chain rules) - rust-lang#139467 (More trivial tweaks) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#139456 - calebcartwright:style-let-chains-final, r=joshtriplett style guide: add let-chain rules Reopens rust-lang#110568 refs rust-lang#53667 and I suppose rust-lang#132833 as well This reflects the style rules that the style team had already agreed upon back in 2023, with the addition of literals in the lhs being permissible for single line formatting, and the removal of unnecessary language/example snippets around non-`&&` operators that was a small hiccup in the original PR. It also reflects current formatting behavior implemented in rustfmt (though note that the adjustment to include literals has been implemented & merged, but is still pending a sync to nightly)
Reopens #110568
refs #53667 and I suppose #132833 as well
This reflects the style rules that the style team had already agreed upon back in 2023, with the addition of literals in the lhs being permissible for single line formatting, and the removal of unnecessary language/example snippets around non-
&&
operators that was a small hiccup in the original PR.It also reflects current formatting behavior implemented in rustfmt (though note that the adjustment to include literals has been implemented & merged, but is still pending a sync to nightly)