Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,15 @@ impl<'a> ControlFlow<'a> {
.config
.max_width()
.saturating_sub(constr_shape.used_width() + offset + brace_overhead);
let first_line_indent = if context.config.style_edition() >= StyleEdition::Edition2027 {
shape.indent.width()
} else {
shape.used_width()
};
let force_newline_brace = (pat_expr_string.contains('\n')
|| pat_expr_string.len() > one_line_budget)
&& (!last_line_extendable(&pat_expr_string)
|| last_line_offsetted(shape.used_width(), &pat_expr_string));
|| last_line_offsetted(first_line_indent, &pat_expr_string));

// Try to format if-else on single line.
if self.allow_single_line && context.config.single_line_if_else_max_width() > 0 {
Expand Down
14 changes: 14 additions & 0 deletions tests/source/issue_7003_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rustfmt-style_edition: 2024

fn main() {
_ = if let Some(term_node) = sema
.token_ancestors_with_macros(token.clone())
.find(|node| {
matches!(
node.kind(),
BLOCK_EXPR | ARG_LIST | PAREN_EXPR | ARRAY_EXPR | MATCH_EXPR
)
}) {
match term_node.kind() {}
};
}
14 changes: 14 additions & 0 deletions tests/source/issue_7003_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rustfmt-style_edition: 2027

fn main() {
_ = if let Some(term_node) = sema
.token_ancestors_with_macros(token.clone())
.find(|node| {
matches!(
node.kind(),
BLOCK_EXPR | ARG_LIST | PAREN_EXPR | ARRAY_EXPR | MATCH_EXPR
)
}) {
match term_node.kind() {}
};
}
14 changes: 14 additions & 0 deletions tests/target/issue_7003_style_edition_2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rustfmt-style_edition: 2024

fn main() {
_ = if let Some(term_node) = sema
.token_ancestors_with_macros(token.clone())
.find(|node| {
matches!(
node.kind(),
BLOCK_EXPR | ARG_LIST | PAREN_EXPR | ARRAY_EXPR | MATCH_EXPR
)
}) {
match term_node.kind() {}
};
}
15 changes: 15 additions & 0 deletions tests/target/issue_7003_style_edition_2027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-style_edition: 2027

fn main() {
_ = if let Some(term_node) = sema
.token_ancestors_with_macros(token.clone())
.find(|node| {
matches!(
node.kind(),
BLOCK_EXPR | ARG_LIST | PAREN_EXPR | ARRAY_EXPR | MATCH_EXPR
)
})
{
match term_node.kind() {}
};
}