Skip to content

Commit d74fe2e

Browse files
committed
is_else_cause: don't use hir_parent_iter just to go one level up
1 parent 49e2f37 commit d74fe2e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

clippy_utils/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,16 +1349,13 @@ pub fn peel_blocks_with_stmt<'a>(mut expr: &'a Expr<'a>) -> &'a Expr<'a> {
13491349

13501350
/// Checks if the given expression is the else clause of either an `if` or `if let` expression.
13511351
pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
1352-
let mut iter = tcx.hir_parent_iter(expr.hir_id);
1353-
match iter.next() {
1354-
Some((
1355-
_,
1356-
Node::Expr(Expr {
1357-
kind: ExprKind::If(_, _, Some(else_expr)),
1358-
..
1359-
}),
1360-
)) => else_expr.hir_id == expr.hir_id,
1361-
_ => false,
1352+
if let Node::Expr(expr) = tcx.parent_hir_node(expr.hir_id)
1353+
&& let ExprKind::If(_, _, Some(else_expr)) = expr.kind
1354+
&& else_expr.hir_id == expr.hir_id
1355+
{
1356+
true
1357+
} else {
1358+
false
13621359
}
13631360
}
13641361

0 commit comments

Comments
 (0)