diff --git a/src/items.rs b/src/items.rs index fe35953715c..d5bc38303e0 100644 --- a/src/items.rs +++ b/src/items.rs @@ -127,8 +127,8 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option 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, diff --git a/tests/target/configs/single_line_let_else_max_width/100.rs b/tests/target/configs/single_line_let_else_max_width/100.rs index 2310ff8a228..0409124a5b0 100644 --- a/tests/target/configs/single_line_let_else_max_width/100.rs +++ b/tests/target/configs/single_line_let_else_max_width/100.rs @@ -24,7 +24,8 @@ fn main() { upper, step, range: _, - }) = slice.as_ref() else { + }) = slice.as_ref() + else { return; }; diff --git a/tests/target/configs/single_line_let_else_max_width/50.rs b/tests/target/configs/single_line_let_else_max_width/50.rs index df2c40d72d6..6afc2b6f2b0 100644 --- a/tests/target/configs/single_line_let_else_max_width/50.rs +++ b/tests/target/configs/single_line_let_else_max_width/50.rs @@ -26,7 +26,8 @@ fn main() { upper, step, range: _, - }) = slice.as_ref() else { + }) = slice.as_ref() + else { return; }; diff --git a/tests/target/configs/single_line_let_else_max_width/zero.rs b/tests/target/configs/single_line_let_else_max_width/zero.rs index f4d26ad3757..b5fd0b9edaf 100644 --- a/tests/target/configs/single_line_let_else_max_width/zero.rs +++ b/tests/target/configs/single_line_let_else_max_width/zero.rs @@ -30,7 +30,8 @@ fn main() { upper, step, range: _, - }) = slice.as_ref() else { + }) = slice.as_ref() + else { return; };