Skip to content

Commit 9d0428c

Browse files
committed
Source code for example from issue #6202
Target code from example issue #6202 Corrected indentation and use of spacing for resriting let statements Modified resrite_let to account for trailing ' =' Reduced configs down to what was necessary to reproduce issue Reduced configs down to what was necessary to reproduce issue Documented reason for modifying pat_shape to account for ' =' Moved comment to match rest of codebase's style Fixed issue with accounting for trailing ' =' in let statements
1 parent 6093d48 commit 9d0428c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/expr.rs

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

18621862
// 4 = "let ".len()
1863-
let pat_shape = shape.offset_left(4)?;
1863+
let mut pat_shape = shape.offset_left(4)?;
1864+
if context.config.version() == Version::Two {
1865+
// 2 to account for the length of " ="
1866+
pat_shape = pat_shape.sub_width(2)?;
1867+
}
18641868
let pat_str = pat.rewrite(context, pat_shape)?;
18651869
result.push_str(&pat_str);
18661870

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

0 commit comments

Comments
 (0)