Skip to content

Commit 5722a7d

Browse files
camsteffenflip1995
authored andcommitted
Fix manual_match with let-expressions
1 parent 61bb967 commit 5722a7d

File tree

4 files changed

+191
-211
lines changed

4 files changed

+191
-211
lines changed

clippy_lints/src/collapsible_match.rs

Lines changed: 3 additions & 29 deletions
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};
@@ -149,33 +150,6 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir>
149150
expr
150151
}
151152

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

0 commit comments

Comments
 (0)