Skip to content

Commit

Permalink
wrap else to next line if let-else pattern is multi-lined
Browse files Browse the repository at this point in the history
This rule wasn't explicity stated in the style guide so it was missed,
but luckily we caught it during testing.
  • Loading branch information
ytmimi authored and calebcartwright committed Jul 1, 2023
1 parent 7b4e8a6 commit 1de65a2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl Rewrite for ast::Local {

if let Some(block) = else_block {
let else_kw_span = init.span.between(block.span);
let force_newline_else =
!same_line_else_kw_and_brace(&result, context, else_kw_span, nested_shape);
let force_newline_else = pat_str.contains('\n')
|| !same_line_else_kw_and_brace(&result, context, else_kw_span, nested_shape);
let else_kw = rewrite_else_kw_with_comments(
force_newline_else,
true,
Expand Down
3 changes: 2 additions & 1 deletion tests/target/configs/single_line_let_else_max_width/100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fn main() {
upper,
step,
range: _,
}) = slice.as_ref() else {
}) = slice.as_ref()
else {
return;
};

Expand Down
3 changes: 2 additions & 1 deletion tests/target/configs/single_line_let_else_max_width/50.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ fn main() {
upper,
step,
range: _,
}) = slice.as_ref() else {
}) = slice.as_ref()
else {
return;
};

Expand Down
3 changes: 2 additions & 1 deletion tests/target/configs/single_line_let_else_max_width/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ fn main() {
upper,
step,
range: _,
}) = slice.as_ref() else {
}) = slice.as_ref()
else {
return;
};

Expand Down

0 comments on commit 1de65a2

Please sign in to comment.