@@ -3,8 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context} ;
44use clippy_utils:: ty:: { is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function} ;
55use clippy_utils:: {
6- can_move_expr_to_closure, is_else_clause, is_lang_ctor , is_lint_allowed , path_to_local_id , peel_blocks ,
7- peel_hir_expr_refs, peel_hir_expr_while, CaptureKind ,
6+ can_move_expr_to_closure, is_else_clause, is_lint_allowed , is_res_lang_ctor , path_res , path_to_local_id ,
7+ peel_blocks , peel_hir_expr_refs, peel_hir_expr_while, CaptureKind ,
88} ;
99use rustc_ast:: util:: parser:: PREC_POSTFIX ;
1010use rustc_errors:: Applicability ;
@@ -251,9 +251,11 @@ fn try_parse_pattern<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: Syn
251251 match pat. kind {
252252 PatKind :: Wild => Some ( OptionPat :: Wild ) ,
253253 PatKind :: Ref ( pat, _) => f ( cx, pat, ref_count + 1 , ctxt) ,
254- PatKind :: Path ( ref qpath) if is_lang_ctor ( cx, qpath, OptionNone ) => Some ( OptionPat :: None ) ,
254+ PatKind :: Path ( ref qpath) if is_res_lang_ctor ( cx, cx. qpath_res ( qpath, pat. hir_id ) , OptionNone ) => {
255+ Some ( OptionPat :: None )
256+ } ,
255257 PatKind :: TupleStruct ( ref qpath, [ pattern] , _)
256- if is_lang_ctor ( cx, qpath, OptionSome ) && pat. span . ctxt ( ) == ctxt =>
258+ if is_res_lang_ctor ( cx, cx . qpath_res ( qpath, pat . hir_id ) , OptionSome ) && pat. span . ctxt ( ) == ctxt =>
257259 {
258260 Some ( OptionPat :: Some { pattern, ref_count } )
259261 } ,
@@ -272,16 +274,14 @@ fn get_some_expr<'tcx>(
272274) -> Option < SomeExpr < ' tcx > > {
273275 // TODO: Allow more complex expressions.
274276 match expr. kind {
275- ExprKind :: Call (
276- Expr {
277- kind : ExprKind :: Path ( ref qpath) ,
278- ..
279- } ,
280- [ arg] ,
281- ) if ctxt == expr. span . ctxt ( ) && is_lang_ctor ( cx, qpath, OptionSome ) => Some ( SomeExpr {
282- expr : arg,
283- needs_unsafe_block,
284- } ) ,
277+ ExprKind :: Call ( callee, [ arg] )
278+ if ctxt == expr. span . ctxt ( ) && is_res_lang_ctor ( cx, path_res ( cx, callee) , OptionSome ) =>
279+ {
280+ Some ( SomeExpr {
281+ expr : arg,
282+ needs_unsafe_block,
283+ } )
284+ } ,
285285 ExprKind :: Block (
286286 Block {
287287 stmts : [ ] ,
@@ -302,5 +302,5 @@ fn get_some_expr<'tcx>(
302302
303303// Checks for the `None` value.
304304fn is_none_expr ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
305- matches ! ( peel_blocks ( expr ) . kind , ExprKind :: Path ( ref qpath ) if is_lang_ctor ( cx, qpath , OptionNone ) )
305+ is_res_lang_ctor ( cx , path_res ( cx, peel_blocks ( expr ) ) , OptionNone )
306306}
0 commit comments