From cc07f68cd5d57bda305f419c529b93e2a9f5d680 Mon Sep 17 00:00:00 2001 From: ynishimi Date: Fri, 30 May 2025 18:55:59 +0900 Subject: [PATCH] fix: split a line exceeding the maximum width --- src/expr.rs | 6 +++++- tests/source/issue-6202/long_pat.rs | 14 ++++++++++++++ tests/target/issue-6202/long_pat.rs | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-6202/long_pat.rs create mode 100644 tests/target/issue-6202/long_pat.rs diff --git a/src/expr.rs b/src/expr.rs index ec96b3edce8..348cffc21ee 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1996,7 +1996,11 @@ fn rewrite_let( // TODO(ytmimi) comments could appear between `let` and the `pat` // 4 = "let ".len() - let pat_shape = shape.offset_left(4, pat.span)?; + let mut pat_shape = shape.offset_left(4, pat.span)?; + if context.config.style_edition() >= StyleEdition::Edition2027 { + // 2 for the length of " =" + pat_shape = pat_shape.sub_width(2, pat.span)?; + } let pat_str = pat.rewrite_result(context, pat_shape)?; result.push_str(&pat_str); diff --git a/tests/source/issue-6202/long_pat.rs b/tests/source/issue-6202/long_pat.rs new file mode 100644 index 00000000000..a7f47f32cb2 --- /dev/null +++ b/tests/source/issue-6202/long_pat.rs @@ -0,0 +1,14 @@ +// max_width = 120 +// error_on_line_overflow = true +// style_edition = "2027" + +impl EarlyLintPass for NeedlessContinue { + fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { + if let ExprKind::Loop(body, label, ..) | ExprKind::While(_, body, label) | ExprKind::ForLoop { body, label, .. } = + &expr.kind + && !in_external_macro(cx.sess, expr.span) + { + check_final_block_stmt(cx, body, label, expr.span.ctxt()); + } + } +} \ No newline at end of file diff --git a/tests/target/issue-6202/long_pat.rs b/tests/target/issue-6202/long_pat.rs new file mode 100644 index 00000000000..fef118a9da2 --- /dev/null +++ b/tests/target/issue-6202/long_pat.rs @@ -0,0 +1,15 @@ +// max_width = 120 +// error_on_line_overflow = true +// style_edition = "2027" + +impl EarlyLintPass for NeedlessContinue { + fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { + if let ExprKind::Loop(body, label, ..) + | ExprKind::While(_, body, label) + | ExprKind::ForLoop { body, label, .. } = &expr.kind + && !in_external_macro(cx.sess, expr.span) + { + check_final_block_stmt(cx, body, label, expr.span.ctxt()); + } + } +}