Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,11 @@ fn rewrite_let(
// TODO(ytmimi) comments could appear between `let` and the `pat`

// 4 = "let ".len()
let pat_shape = shape.offset_left(4)?;
let mut pat_shape = shape.offset_left(4)?;
if context.config.version() == Version::Two {
// 2 to account for the length of " ="
pat_shape = pat_shape.sub_width(2)?;
}
let pat_str = pat.rewrite(context, pat_shape)?;
result.push_str(&pat_str);

Expand Down
13 changes: 13 additions & 0 deletions tests/source/issue-6202/issue_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-max_width: 120
// rustfmt-version: Two

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());
}
}
}
14 changes: 14 additions & 0 deletions tests/target/issue-6202/issue_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rustfmt-max_width: 120
// rustfmt-version: Two

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());
}
}
}