@@ -3,8 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
3
3
use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context} ;
4
4
use clippy_utils:: ty:: { is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function} ;
5
5
use 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 ,
8
8
} ;
9
9
use rustc_ast:: util:: parser:: PREC_POSTFIX ;
10
10
use rustc_errors:: Applicability ;
@@ -251,9 +251,11 @@ fn try_parse_pattern<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: Syn
251
251
match pat. kind {
252
252
PatKind :: Wild => Some ( OptionPat :: Wild ) ,
253
253
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
+ } ,
255
257
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 =>
257
259
{
258
260
Some ( OptionPat :: Some { pattern, ref_count } )
259
261
} ,
@@ -272,16 +274,14 @@ fn get_some_expr<'tcx>(
272
274
) -> Option < SomeExpr < ' tcx > > {
273
275
// TODO: Allow more complex expressions.
274
276
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
+ } ,
285
285
ExprKind :: Block (
286
286
Block {
287
287
stmts : [ ] ,
@@ -302,5 +302,5 @@ fn get_some_expr<'tcx>(
302
302
303
303
// Checks for the `None` value.
304
304
fn 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 )
306
306
}
0 commit comments