mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Fix formatting of let chains
This commit is contained in:
parent
93b5c893e6
commit
ba951e3ca7
1 changed files with 10 additions and 8 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue