|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then;
|
2 | 2 | use clippy_utils::higher::IfLetOrMatch;
|
3 | 3 | use clippy_utils::visitors::is_local_used;
|
4 |
| -use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_ref_operators, SpanlessEq}; |
| 4 | +use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq}; |
5 | 5 | use if_chain::if_chain;
|
6 | 6 | use rustc_hir::LangItem::OptionNone;
|
7 |
| -use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind}; |
| 7 | +use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind}; |
8 | 8 | use rustc_lint::{LateContext, LateLintPass};
|
9 | 9 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
10 | 10 | use rustc_span::{MultiSpan, Span};
|
@@ -75,7 +75,7 @@ fn check_arm<'tcx>(
|
75 | 75 | outer_guard: Option<&'tcx Guard<'tcx>>,
|
76 | 76 | outer_else_body: Option<&'tcx Expr<'tcx>>,
|
77 | 77 | ) {
|
78 |
| - let inner_expr = strip_singleton_blocks(outer_then_body); |
| 78 | + let inner_expr = peel_blocks_with_stmt(outer_then_body); |
79 | 79 | if_chain! {
|
80 | 80 | if let Some(inner) = IfLetOrMatch::parse(cx, inner_expr);
|
81 | 81 | if let Some((inner_scrutinee, inner_then_pat, inner_else_body)) = match inner {
|
@@ -138,20 +138,6 @@ fn check_arm<'tcx>(
|
138 | 138 | }
|
139 | 139 | }
|
140 | 140 |
|
141 |
| -fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> { |
142 |
| - while let ExprKind::Block(block, _) = expr.kind { |
143 |
| - match (block.stmts, block.expr) { |
144 |
| - ([stmt], None) => match stmt.kind { |
145 |
| - StmtKind::Expr(e) | StmtKind::Semi(e) => expr = e, |
146 |
| - _ => break, |
147 |
| - }, |
148 |
| - ([], Some(e)) => expr = e, |
149 |
| - _ => break, |
150 |
| - } |
151 |
| - } |
152 |
| - expr |
153 |
| -} |
154 |
| - |
155 | 141 | /// A "wild-like" arm has a wild (`_`) or `None` pattern and no guard. Such arms can be "collapsed"
|
156 | 142 | /// into a single wild arm without any significant loss in semantics or readability.
|
157 | 143 | fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
|
|
0 commit comments