@@ -5,14 +5,14 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
55use clippy_utils:: sugg:: Sugg ;
66use clippy_utils:: ty:: { is_copy, is_unsafe_fn, peel_and_count_ty_refs} ;
77use clippy_utils:: {
8- CaptureKind , can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, peel_blocks ,
9- peel_hir_expr_refs, peel_hir_expr_while,
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,
1010} ;
1111use rustc_ast:: util:: parser:: ExprPrecedence ;
1212use rustc_errors:: Applicability ;
13- use rustc_hir:: LangItem :: { OptionNone , OptionSome } ;
13+ use rustc_hir:: LangItem :: OptionNone ;
1414use rustc_hir:: def:: Res ;
15- use rustc_hir:: { BindingMode , Expr , ExprKind , HirId , Mutability , Pat , PatExpr , PatExprKind , PatKind , Path , QPath } ;
15+ use rustc_hir:: { BindingMode , Expr , ExprKind , HirId , Mutability , Pat , PatKind , Path , QPath } ;
1616use rustc_lint:: LateContext ;
1717use rustc_span:: { SyntaxContext , sym} ;
1818
@@ -255,23 +255,9 @@ pub(super) fn try_parse_pattern<'tcx>(
255255 match pat. kind {
256256 PatKind :: Wild => Some ( OptionPat :: Wild ) ,
257257 PatKind :: Ref ( pat, _) => f ( cx, pat, ref_count + 1 , ctxt) ,
258- PatKind :: Expr ( PatExpr {
259- kind : PatExprKind :: Path ( qpath) ,
260- hir_id,
261- ..
262- } ) if cx
263- . qpath_res ( qpath, * hir_id)
264- . ctor_parent ( cx)
265- . is_lang_item ( cx, OptionNone ) =>
266- {
267- Some ( OptionPat :: None )
268- } ,
269- PatKind :: TupleStruct ( ref qpath, [ pattern] , _)
270- if cx
271- . qpath_res ( qpath, pat. hir_id )
272- . ctor_parent ( cx)
273- . is_lang_item ( cx, OptionSome )
274- && pat. span . ctxt ( ) == ctxt =>
258+ _ if is_none_pattern ( cx, pat) => Some ( OptionPat :: None ) ,
259+ _ if let Some ( [ pattern] ) = as_some_pattern ( cx, pat)
260+ && pat. span . ctxt ( ) == ctxt =>
275261 {
276262 Some ( OptionPat :: Some { pattern, ref_count } )
277263 } ,
0 commit comments