Skip to content
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: Clarify let-else further #113139

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/doc/style-guide/src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ before the `else`.

If the initializer expression is multi-line, the `else` keyword and opening
brace of the block (i.e. `else {`) should be put on the same line as the end of
the initializer expression, with a space between them, if all the following are
true:
the initializer expression, with a space between them, if and only if all the
following are true:
Comment on lines 160 to +163
Copy link
Member

@calebcartwright calebcartwright Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the ambiguity comes from the fact that this all starts with the "if the initializer expression is multi-line" up on line 160, as that could be read as meaning the text that follows is not applicable if the expr itself is single line.

I'll think on some additional text proposals, but wanted to go ahead and share that.

Copy link
Member Author

@joshtriplett joshtriplett Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, but in the single-line case it doesn't matter if you try to apply these rules or not; the three conditions can't possibly hold for a single-line initializer. You can't have a single-line initializer expression that consists of nothing but closing parentheses, square brackets, and/or braces.

So, whether you look at this case and go "doesn't apply because it's not multi-line" or look at this case and go "doesn't apply because the conditions don't hold", either way you go on to the next case.


* The initializer expression ends with one or more closing
parentheses, square brackets, and/or braces
Expand Down Expand Up @@ -209,6 +209,28 @@ fn main() {
else {
return;
};

let LongStructName(AnotherStruct {
multi,
line,
pattern,
}) = slice.as_ref()
else {
return;
};

let LongStructName(AnotherStruct {
multi,
line,
pattern,
}) = multi_line_function_call(
arg1,
arg2,
arg3,
arg4,
) else {
return;
};
}
```

Expand Down
Loading