|
1 | 1 | use crate::map_unit_fn::OPTION_MAP_UNIT_FN; |
2 | 2 | use crate::matches::MATCH_AS_REF; |
3 | | -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; |
| 3 | +use clippy_utils::res::{MaybeDef, MaybeResPath}; |
4 | 4 | use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; |
5 | 5 | use clippy_utils::sugg::Sugg; |
6 | 6 | use clippy_utils::ty::{is_copy, is_unsafe_fn, peel_and_count_ty_refs}; |
7 | 7 | use clippy_utils::{ |
8 | 8 | CaptureKind, as_some_pattern, can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, |
9 | | - is_none_pattern, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, |
| 9 | + is_none_expr, is_none_pattern, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, |
10 | 10 | }; |
11 | 11 | use rustc_ast::util::parser::ExprPrecedence; |
12 | 12 | use rustc_errors::Applicability; |
13 | | -use rustc_hir::LangItem::OptionNone; |
14 | 13 | use rustc_hir::def::Res; |
15 | 14 | use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath}; |
16 | 15 | use rustc_lint::LateContext; |
@@ -44,16 +43,16 @@ where |
44 | 43 | try_parse_pattern(cx, then_pat, expr_ctxt), |
45 | 44 | else_pat.map_or(Some(OptionPat::Wild), |p| try_parse_pattern(cx, p, expr_ctxt)), |
46 | 45 | ) { |
47 | | - (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => { |
| 46 | + (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) if is_none_arm_body(cx, then_body) => { |
48 | 47 | (else_body, pattern, ref_count, true) |
49 | 48 | }, |
50 | | - (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => { |
| 49 | + (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) if is_none_arm_body(cx, then_body) => { |
51 | 50 | (else_body, pattern, ref_count, false) |
52 | 51 | }, |
53 | | - (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) if is_none_expr(cx, else_body) => { |
| 52 | + (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) if is_none_arm_body(cx, else_body) => { |
54 | 53 | (then_body, pattern, ref_count, true) |
55 | 54 | }, |
56 | | - (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) if is_none_expr(cx, else_body) => { |
| 55 | + (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) if is_none_arm_body(cx, else_body) => { |
57 | 56 | (then_body, pattern, ref_count, false) |
58 | 57 | }, |
59 | 58 | _ => return None, |
@@ -268,6 +267,6 @@ pub(super) fn try_parse_pattern<'tcx>( |
268 | 267 | } |
269 | 268 |
|
270 | 269 | /// Checks for the `None` value, possibly in a block. |
271 | | -fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { |
272 | | - peel_blocks(expr).res(cx).ctor_parent(cx).is_lang_item(cx, OptionNone) |
| 270 | +fn is_none_arm_body(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { |
| 271 | + is_none_expr(cx, peel_blocks(expr)) |
273 | 272 | } |
0 commit comments