Skip to content

Commit 9309ce0

Browse files
committed
Fix manual_match with let-expressions
1 parent 053e004 commit 9309ce0

File tree

4 files changed

+191
-211
lines changed

4 files changed

+191
-211
lines changed

clippy_lints/src/collapsible_match.rs

+3-29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::higher::IfLetOrMatch;
23
use clippy_utils::visitors::is_local_used;
3-
use clippy_utils::{higher, 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_ref_operators, SpanlessEq};
45
use if_chain::if_chain;
56
use rustc_hir::LangItem::OptionNone;
6-
use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, MatchSource, Pat, PatKind, StmtKind};
7+
use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind};
78
use rustc_lint::{LateContext, LateLintPass};
89
use rustc_session::{declare_lint_pass, declare_tool_lint};
910
use rustc_span::{MultiSpan, Span};
@@ -150,33 +151,6 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir>
150151
expr
151152
}
152153

153-
enum IfLetOrMatch<'hir> {
154-
Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource),
155-
/// scrutinee, pattern, then block, else block
156-
IfLet(
157-
&'hir Expr<'hir>,
158-
&'hir Pat<'hir>,
159-
&'hir Expr<'hir>,
160-
Option<&'hir Expr<'hir>>,
161-
),
162-
}
163-
164-
impl<'hir> IfLetOrMatch<'hir> {
165-
fn parse(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option<Self> {
166-
match expr.kind {
167-
ExprKind::Match(expr, arms, source) => Some(Self::Match(expr, arms, source)),
168-
_ => higher::IfLet::hir(cx, expr).map(
169-
|higher::IfLet {
170-
let_expr,
171-
let_pat,
172-
if_then,
173-
if_else,
174-
}| { Self::IfLet(let_expr, let_pat, if_then, if_else) },
175-
),
176-
}
177-
}
178-
}
179-
180154
/// A "wild-like" arm has a wild (`_`) or `None` pattern and no guard. Such arms can be "collapsed"
181155
/// into a single wild arm without any significant loss in semantics or readability.
182156
fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {

0 commit comments

Comments
 (0)