Skip to content

Commit 7b4e8a6

Browse files
ytmimicalebcartwright
authored andcommitted
update else_block_exceeds_width calculation in let-else rewrite
By reversing the logic I felt that the code became a clearer. Also, added a comment to make it clear that we need to take the trailing semicolon for the `let-else` statement into account.
1 parent fe8b72d commit 7b4e8a6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ impl Rewrite for ast::Local {
156156
rewrite_let_else_block(block, allow_single_line, context, shape)?;
157157

158158
let single_line_else = !rw_else_block.contains('\n');
159-
let else_block_exceeds_width = available_space <= rw_else_block.len();
159+
// +1 for the trailing `;`
160+
let else_block_exceeds_width = rw_else_block.len() + 1 > available_space;
160161

161162
if allow_single_line && single_line_else && else_block_exceeds_width {
162163
// writing this on one line would exceed the available width

0 commit comments

Comments
 (0)