From ba951e3ca72283d39757bd39d20bfd75ce901147 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 15 Nov 2022 18:29:43 +0100 Subject: [PATCH] Fix formatting of let chains --- clippy_lints/src/semicolon_block.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/semicolon_block.rs b/clippy_lints/src/semicolon_block.rs index 911d38f65..a41f89a6a 100644 --- a/clippy_lints/src/semicolon_block.rs +++ b/clippy_lints/src/semicolon_block.rs @@ -73,9 +73,9 @@ impl LateLintPass<'_> for SemicolonBlock { fn semicolon_inside_block(cx: &LateContext<'_>, block: &Block<'_>) { if !block.span.from_expansion() - && let Some(tail) = block.expr - && let Some(block_expr @ Expr { kind: ExprKind::Block(_, _), ..}) = get_parent_expr_for_hir(cx, block.hir_id) - && let Some(Node::Stmt(Stmt { kind: StmtKind::Semi(_), span, .. })) = get_parent_node(cx.tcx, block_expr.hir_id) + && let Some(tail) = block.expr + && let Some(block_expr @ Expr { kind: ExprKind::Block(_, _), ..}) = get_parent_expr_for_hir(cx, block.hir_id) + && let Some(Node::Stmt(Stmt { kind: StmtKind::Semi(_), span, .. })) = get_parent_node(cx.tcx, block_expr.hir_id) { let expr_snip = snippet_with_macro_callsite(cx, tail.span, ".."); @@ -101,16 +101,18 @@ fn semicolon_inside_block(cx: &LateContext<'_>, block: &Block<'_>) { fn semicolon_outside_block(cx: &LateContext<'_>, block: &Block<'_>) { if !block.span.from_expansion() - && block.expr.is_none() - && let [.., Stmt { kind: StmtKind::Semi(expr), .. }] = block.stmts - && let Some(block_expr @ Expr { kind: ExprKind::Block(_, _), ..}) = get_parent_expr_for_hir(cx,block.hir_id) - && let Some(Node::Stmt(Stmt { kind: StmtKind::Expr(_), .. })) = get_parent_node(cx.tcx, block_expr.hir_id) { + && block.expr.is_none() + && let [.., Stmt { kind: StmtKind::Semi(expr), .. }] = block.stmts + && let Some(block_expr @ Expr { kind: ExprKind::Block(_, _), ..}) = get_parent_expr_for_hir(cx,block.hir_id) + && let Some(Node::Stmt(Stmt { kind: StmtKind::Expr(_), .. })) = get_parent_node(cx.tcx, block_expr.hir_id) + { let expr_snip = snippet_with_macro_callsite(cx, expr.span, ".."); let mut suggestion: String = snippet_with_macro_callsite(cx, block.span, "..").to_string(); if let Some((expr_offset, _)) = suggestion.rmatch_indices(&*expr_snip).next() - && let Some(semi_offset) = suggestion[expr_offset + expr_snip.len()..].find(';') { + && let Some(semi_offset) = suggestion[expr_offset + expr_snip.len()..].find(';') + { suggestion.remove(expr_offset + expr_snip.len() + semi_offset); } else { return;