Skip to content

Commit 18f4fa3

Browse files
ynishimiytmimi
authored andcommitted
fix: split a line exceeding the maximum width
1 parent fd0ea74 commit 18f4fa3

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,11 @@ fn rewrite_let(
19961996
// TODO(ytmimi) comments could appear between `let` and the `pat`
19971997

19981998
// 4 = "let ".len()
1999-
let pat_shape = shape.offset_left(4, pat.span)?;
1999+
let mut pat_shape = shape.offset_left(4, pat.span)?;
2000+
if context.config.style_edition() >= StyleEdition::Edition2027 {
2001+
// 2 for the length of " ="
2002+
pat_shape = pat_shape.sub_width(2, pat.span)?;
2003+
}
20002004
let pat_str = pat.rewrite_result(context, pat_shape)?;
20012005
result.push_str(&pat_str);
20022006

tests/source/issue-6202/long_pat.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// max_width = 120
2+
// error_on_line_overflow = true
3+
// style_edition = "2027"
4+
5+
impl EarlyLintPass for NeedlessContinue {
6+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
7+
if let ExprKind::Loop(body, label, ..) | ExprKind::While(_, body, label) | ExprKind::ForLoop { body, label, .. } =
8+
&expr.kind
9+
&& !in_external_macro(cx.sess, expr.span)
10+
{
11+
check_final_block_stmt(cx, body, label, expr.span.ctxt());
12+
}
13+
}
14+
}

tests/target/issue-6202/long_pat.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// max_width = 120
2+
// error_on_line_overflow = true
3+
// style_edition = "2027"
4+
5+
impl EarlyLintPass for NeedlessContinue {
6+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
7+
if let ExprKind::Loop(body, label, ..)
8+
| ExprKind::While(_, body, label)
9+
| ExprKind::ForLoop { body, label, .. } = &expr.kind
10+
&& !in_external_macro(cx.sess, expr.span)
11+
{
12+
check_final_block_stmt(cx, body, label, expr.span.ctxt());
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)