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.
This commit is contained in:
Yacin Tmimi 2023-06-23 00:05:31 -04:00 committed by Caleb Cartwright
parent fe8b72d98e
commit 7b4e8a6d31

View File

@ -156,7 +156,8 @@ impl Rewrite for ast::Local {
rewrite_let_else_block(block, allow_single_line, context, shape)?;
let single_line_else = !rw_else_block.contains('\n');
let else_block_exceeds_width = available_space <= rw_else_block.len();
// +1 for the trailing `;`
let else_block_exceeds_width = rw_else_block.len() + 1 > available_space;
if allow_single_line && single_line_else && else_block_exceeds_width {
// writing this on one line would exceed the available width