mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-25 20:07:21 +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<'_>) {
|
fn semicolon_inside_block(cx: &LateContext<'_>, block: &Block<'_>) {
|
||||||
if !block.span.from_expansion()
|
if !block.span.from_expansion()
|
||||||
&& let Some(tail) = block.expr
|
&& let Some(tail) = block.expr
|
||||||
&& let Some(block_expr @ Expr { kind: ExprKind::Block(_, _), ..}) = get_parent_expr_for_hir(cx, block.hir_id)
|
&& 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(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, "..");
|
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<'_>) {
|
fn semicolon_outside_block(cx: &LateContext<'_>, block: &Block<'_>) {
|
||||||
if !block.span.from_expansion()
|
if !block.span.from_expansion()
|
||||||
&& block.expr.is_none()
|
&& block.expr.is_none()
|
||||||
&& let [.., Stmt { kind: StmtKind::Semi(expr), .. }] = block.stmts
|
&& 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(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 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 expr_snip = snippet_with_macro_callsite(cx, expr.span, "..");
|
||||||
|
|
||||||
let mut suggestion: String = snippet_with_macro_callsite(cx, block.span, "..").to_string();
|
let mut suggestion: String = snippet_with_macro_callsite(cx, block.span, "..").to_string();
|
||||||
|
|
||||||
if let Some((expr_offset, _)) = suggestion.rmatch_indices(&*expr_snip).next()
|
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);
|
suggestion.remove(expr_offset + expr_snip.len() + semi_offset);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue