Skip to content

Commit aecccbc

Browse files
committed
Auto merge of #7047 - camsteffen:lang-ctor, r=flip1995
Introduce `is_lang_ctor` changelog: none Replaces `is_some_ctor` and `is_ok_ctor`. Removes many path usages.
2 parents f0ceb28 + 7468542 commit aecccbc

17 files changed

+121
-157
lines changed

clippy_lints/src/collapsible_match.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::visitors::LocalUsedVisitor;
3-
use clippy_utils::{path_to_local, SpanlessEq};
3+
use clippy_utils::{is_lang_ctor, path_to_local, SpanlessEq};
44
use if_chain::if_chain;
5-
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
6-
use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, QPath, StmtKind, UnOp};
5+
use rustc_hir::LangItem::OptionNone;
6+
use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind, StmtKind, UnOp};
77
use rustc_lint::{LateContext, LateLintPass};
8-
use rustc_middle::ty::{DefIdTree, TyCtxt, TypeckResults};
8+
use rustc_middle::ty::TypeckResults;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010
use rustc_span::{MultiSpan, Span};
1111

@@ -52,7 +52,7 @@ declare_lint_pass!(CollapsibleMatch => [COLLAPSIBLE_MATCH]);
5252
impl<'tcx> LateLintPass<'tcx> for CollapsibleMatch {
5353
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
5454
if let ExprKind::Match(_expr, arms, _source) = expr.kind {
55-
if let Some(wild_arm) = arms.iter().rfind(|arm| arm_is_wild_like(arm, cx.tcx)) {
55+
if let Some(wild_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) {
5656
for arm in arms {
5757
check_arm(arm, wild_arm, cx);
5858
}
@@ -75,7 +75,7 @@ fn check_arm<'tcx>(arm: &Arm<'tcx>, wild_outer_arm: &Arm<'tcx>, cx: &LateContext
7575
// match <local> { .. }
7676
if let Some(binding_id) = path_to_local(strip_ref_operators(expr_in, cx.typeck_results()));
7777
// one of the branches must be "wild-like"
78-
if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| arm_is_wild_like(arm_inner, cx.tcx));
78+
if let Some(wild_inner_arm_idx) = arms_inner.iter().rposition(|arm_inner| arm_is_wild_like(cx, arm_inner));
7979
let (wild_inner_arm, non_wild_inner_arm) =
8080
(&arms_inner[wild_inner_arm_idx], &arms_inner[1 - wild_inner_arm_idx]);
8181
if !pat_contains_or(non_wild_inner_arm.pat);
@@ -126,13 +126,13 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir>
126126
/// A "wild-like" pattern is wild ("_") or `None`.
127127
/// For this lint to apply, both the outer and inner match expressions
128128
/// must have "wild-like" branches that can be combined.
129-
fn arm_is_wild_like(arm: &Arm<'_>, tcx: TyCtxt<'_>) -> bool {
129+
fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
130130
if arm.guard.is_some() {
131131
return false;
132132
}
133133
match arm.pat.kind {
134134
PatKind::Binding(..) | PatKind::Wild => true,
135-
PatKind::Path(QPath::Resolved(None, path)) if is_none_ctor(path.res, tcx) => true,
135+
PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
136136
_ => false,
137137
}
138138
}
@@ -164,17 +164,6 @@ fn pat_contains_or(pat: &Pat<'_>) -> bool {
164164
result
165165
}
166166

167-
fn is_none_ctor(res: Res, tcx: TyCtxt<'_>) -> bool {
168-
if let Some(none_id) = tcx.lang_items().option_none_variant() {
169-
if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = res {
170-
if let Some(variant_id) = tcx.parent(id) {
171-
return variant_id == none_id;
172-
}
173-
}
174-
}
175-
false
176-
}
177-
178167
/// Removes `AddrOf` operators (`&`) or deref operators (`*`), but only if a reference type is
179168
/// dereferenced. An overloaded deref such as `Vec` to slice would not be removed.
180169
fn strip_ref_operators<'hir>(mut expr: &'hir Expr<'hir>, typeck_results: &TypeckResults<'_>) -> &'hir Expr<'hir> {

clippy_lints/src/if_then_some_else_none.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::source::snippet_with_macro_callsite;
3-
use clippy_utils::{match_qpath, meets_msrv, parent_node_is_if_expr};
3+
use clippy_utils::{is_lang_ctor, meets_msrv, parent_node_is_if_expr};
44
use if_chain::if_chain;
5+
use rustc_hir::LangItem::{OptionNone, OptionSome};
56
use rustc_hir::{Expr, ExprKind};
67
use rustc_lint::{LateContext, LateLintPass, LintContext};
78
use rustc_middle::lint::in_external_macro;
@@ -77,12 +78,12 @@ impl LateLintPass<'_> for IfThenSomeElseNone {
7778
if let Some(then_expr) = then_block.expr;
7879
if let ExprKind::Call(then_call, [then_arg]) = then_expr.kind;
7980
if let ExprKind::Path(ref then_call_qpath) = then_call.kind;
80-
if match_qpath(then_call_qpath, &clippy_utils::paths::OPTION_SOME);
81+
if is_lang_ctor(cx, then_call_qpath, OptionSome);
8182
if let ExprKind::Block(els_block, _) = els.kind;
8283
if els_block.stmts.is_empty();
8384
if let Some(els_expr) = els_block.expr;
84-
if let ExprKind::Path(ref els_call_qpath) = els_expr.kind;
85-
if match_qpath(els_call_qpath, &clippy_utils::paths::OPTION_NONE);
85+
if let ExprKind::Path(ref qpath) = els_expr.kind;
86+
if is_lang_ctor(cx, qpath, OptionNone);
8687
then {
8788
let cond_snip = snippet_with_macro_callsite(cx, cond.span, "[condition]");
8889
let cond_snip = if matches!(cond.kind, ExprKind::Unary(_, _) | ExprKind::Binary(_, _, _)) {

clippy_lints/src/loops/manual_flatten.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use super::utils::make_iterator_snippet;
22
use super::MANUAL_FLATTEN;
33
use clippy_utils::diagnostics::span_lint_and_then;
4-
use clippy_utils::{is_ok_ctor, is_some_ctor, path_to_local_id};
4+
use clippy_utils::{is_lang_ctor, path_to_local_id};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, QPath, StmtKind};
7+
use rustc_hir::LangItem::{OptionSome, ResultOk};
8+
use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, StmtKind};
89
use rustc_lint::LateContext;
910
use rustc_middle::ty;
1011
use rustc_span::source_map::Span;
@@ -42,9 +43,9 @@ pub(super) fn check<'tcx>(
4243
if let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind;
4344
if path_to_local_id(match_expr, pat_hir_id);
4445
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
45-
if let PatKind::TupleStruct(QPath::Resolved(None, path), _, _) = match_arms[0].pat.kind;
46-
let some_ctor = is_some_ctor(cx, path.res);
47-
let ok_ctor = is_ok_ctor(cx, path.res);
46+
if let PatKind::TupleStruct(ref qpath, _, _) = match_arms[0].pat.kind;
47+
let some_ctor = is_lang_ctor(cx, qpath, OptionSome);
48+
let ok_ctor = is_lang_ctor(cx, qpath, ResultOk);
4849
if some_ctor || ok_ctor;
4950
then {
5051
let if_let_type = if some_ctor { "Some" } else { "Ok" };

clippy_lints/src/manual_map.rs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
44
use clippy_utils::ty::{can_partially_move_ty, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
5-
use clippy_utils::{in_constant, is_allowed, is_else_clause, match_def_path, match_var, paths, peel_hir_expr_refs};
5+
use clippy_utils::{in_constant, is_allowed, is_else_clause, is_lang_ctor, match_var, peel_hir_expr_refs};
66
use rustc_ast::util::parser::PREC_POSTFIX;
77
use rustc_errors::Applicability;
8+
use rustc_hir::LangItem::{OptionNone, OptionSome};
89
use rustc_hir::{
910
def::Res,
1011
intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor},
@@ -269,20 +270,9 @@ fn try_parse_pattern(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxCon
269270
match pat.kind {
270271
PatKind::Wild => Some(OptionPat::Wild),
271272
PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
272-
PatKind::Path(QPath::Resolved(None, path))
273-
if path
274-
.res
275-
.opt_def_id()
276-
.map_or(false, |id| match_def_path(cx, id, &paths::OPTION_NONE)) =>
277-
{
278-
Some(OptionPat::None)
279-
},
280-
PatKind::TupleStruct(QPath::Resolved(None, path), [pattern], _)
281-
if path
282-
.res
283-
.opt_def_id()
284-
.map_or(false, |id| match_def_path(cx, id, &paths::OPTION_SOME))
285-
&& pat.span.ctxt() == ctxt =>
273+
PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone) => Some(OptionPat::None),
274+
PatKind::TupleStruct(ref qpath, [pattern], _)
275+
if is_lang_ctor(cx, qpath, OptionSome) && pat.span.ctxt() == ctxt =>
286276
{
287277
Some(OptionPat::Some { pattern, ref_count })
288278
},
@@ -298,17 +288,11 @@ fn get_some_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ctxt: SyntaxConte
298288
match expr.kind {
299289
ExprKind::Call(
300290
Expr {
301-
kind: ExprKind::Path(QPath::Resolved(None, path)),
291+
kind: ExprKind::Path(ref qpath),
302292
..
303293
},
304294
[arg],
305-
) if ctxt == expr.span.ctxt() => {
306-
if match_def_path(cx, path.res.opt_def_id()?, &paths::OPTION_SOME) {
307-
Some(arg)
308-
} else {
309-
None
310-
}
311-
},
295+
) if ctxt == expr.span.ctxt() && is_lang_ctor(cx, qpath, OptionSome) => Some(arg),
312296
ExprKind::Block(
313297
Block {
314298
stmts: [],
@@ -324,10 +308,7 @@ fn get_some_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ctxt: SyntaxConte
324308
// Checks for the `None` value.
325309
fn is_none_expr(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
326310
match expr.kind {
327-
ExprKind::Path(QPath::Resolved(None, path)) => path
328-
.res
329-
.opt_def_id()
330-
.map_or(false, |id| match_def_path(cx, id, &paths::OPTION_NONE)),
311+
ExprKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
331312
ExprKind::Block(
332313
Block {
333314
stmts: [],

clippy_lints/src/manual_ok_or.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
33
use clippy_utils::ty::is_type_diagnostic_item;
4-
use clippy_utils::{match_qpath, path_to_local_id, paths};
4+
use clippy_utils::{is_lang_ctor, path_to_local_id};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7+
use rustc_hir::LangItem::{ResultErr, ResultOk};
78
use rustc_hir::{Expr, ExprKind, PatKind};
89
use rustc_lint::LintContext;
910
use rustc_lint::{LateContext, LateLintPass};
@@ -54,7 +55,7 @@ impl LateLintPass<'_> for ManualOkOr {
5455
let or_expr = &args[1];
5556
if is_ok_wrapping(cx, &args[2]);
5657
if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, &[ref err_arg]) = or_expr.kind;
57-
if match_qpath(err_path, &paths::RESULT_ERR);
58+
if is_lang_ctor(cx, err_path, ResultErr);
5859
if let Some(method_receiver_snippet) = snippet_opt(cx, method_receiver.span);
5960
if let Some(err_arg_snippet) = snippet_opt(cx, err_arg.span);
6061
if let Some(indent) = indent_of(cx, scrutinee.span);
@@ -81,7 +82,7 @@ impl LateLintPass<'_> for ManualOkOr {
8182

8283
fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8384
if let ExprKind::Path(ref qpath) = map_expr.kind {
84-
if match_qpath(qpath, &paths::RESULT_OK) {
85+
if is_lang_ctor(cx, qpath, ResultOk) {
8586
return true;
8687
}
8788
}
@@ -90,7 +91,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
9091
let body = cx.tcx.hir().body(body_id);
9192
if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
9293
if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;
93-
if match_qpath(ok_path, &paths::RESULT_OK);
94+
if is_lang_ctor(cx, ok_path, ResultOk);
9495
then { path_to_local_id(ok_arg, param_id) } else { false }
9596
}
9697
}

clippy_lints/src/manual_unwrap_or.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
44
use clippy_utils::ty::is_type_diagnostic_item;
55
use clippy_utils::usage::contains_return_break_continue_macro;
6-
use clippy_utils::{in_constant, match_qpath, path_to_local_id, paths, sugg};
6+
use clippy_utils::{in_constant, is_lang_ctor, path_to_local_id, sugg};
77
use if_chain::if_chain;
88
use rustc_errors::Applicability;
9-
use rustc_hir::{Arm, Expr, ExprKind, Pat, PatKind};
9+
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
10+
use rustc_hir::{Arm, Expr, ExprKind, PatKind};
1011
use rustc_lint::LintContext;
1112
use rustc_lint::{LateContext, LateLintPass};
1213
use rustc_middle::lint::in_external_macro;
@@ -68,23 +69,21 @@ impl Case {
6869
}
6970

7071
fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
71-
fn applicable_or_arm<'a>(arms: &'a [Arm<'a>]) -> Option<&'a Arm<'a>> {
72+
fn applicable_or_arm<'a>(cx: &LateContext<'_>, arms: &'a [Arm<'a>]) -> Option<&'a Arm<'a>> {
7273
if_chain! {
7374
if arms.len() == 2;
7475
if arms.iter().all(|arm| arm.guard.is_none());
75-
if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)|
76+
if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| {
7677
match arm.pat.kind {
77-
PatKind::Path(ref some_qpath) =>
78-
match_qpath(some_qpath, &paths::OPTION_NONE),
79-
PatKind::TupleStruct(ref err_qpath, &[Pat { kind: PatKind::Wild, .. }], _) =>
80-
match_qpath(err_qpath, &paths::RESULT_ERR),
78+
PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
79+
PatKind::TupleStruct(ref qpath, &[pat], _) =>
80+
matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr),
8181
_ => false,
8282
}
83-
);
83+
});
8484
let unwrap_arm = &arms[1 - idx];
85-
if let PatKind::TupleStruct(ref unwrap_qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind;
86-
if match_qpath(unwrap_qpath, &paths::OPTION_SOME)
87-
|| match_qpath(unwrap_qpath, &paths::RESULT_OK);
85+
if let PatKind::TupleStruct(ref qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind;
86+
if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
8887
if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind;
8988
if path_to_local_id(unwrap_arm.body, binding_hir_id);
9089
if !contains_return_break_continue_macro(or_arm.body);
@@ -106,7 +105,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
106105
} else {
107106
None
108107
};
109-
if let Some(or_arm) = applicable_or_arm(match_arms);
108+
if let Some(or_arm) = applicable_or_arm(cx, match_arms);
110109
if let Some(or_body_snippet) = snippet_opt(cx, or_arm.body.span);
111110
if let Some(indent) = indent_of(cx, expr.span);
112111
if constant_simple(cx, cx.typeck_results(), or_arm.body).is_some();

clippy_lints/src/matches.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use clippy_utils::sugg::Sugg;
77
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs};
88
use clippy_utils::visitors::LocalUsedVisitor;
99
use clippy_utils::{
10-
get_parent_expr, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, meets_msrv, path_to_local,
10+
get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, path_to_local,
1111
path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks, strip_pat_refs,
1212
};
1313
use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash};
1414
use if_chain::if_chain;
1515
use rustc_ast::ast::LitKind;
1616
use rustc_errors::Applicability;
1717
use rustc_hir::def::{CtorKind, DefKind, Res};
18+
use rustc_hir::LangItem::{OptionNone, OptionSome};
1819
use rustc_hir::{
1920
self as hir, Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Guard, HirId, Local, MatchSource,
2021
Mutability, Node, Pat, PatKind, PathSegment, QPath, RangeEnd, TyKind,
@@ -1189,10 +1190,10 @@ fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], e
11891190

11901191
fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
11911192
if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
1192-
let arm_ref: Option<BindingAnnotation> = if is_none_arm(&arms[0]) {
1193-
is_ref_some_arm(&arms[1])
1194-
} else if is_none_arm(&arms[1]) {
1195-
is_ref_some_arm(&arms[0])
1193+
let arm_ref: Option<BindingAnnotation> = if is_none_arm(cx, &arms[0]) {
1194+
is_ref_some_arm(cx, &arms[1])
1195+
} else if is_none_arm(cx, &arms[1]) {
1196+
is_ref_some_arm(cx, &arms[0])
11961197
} else {
11971198
None
11981199
};
@@ -1575,20 +1576,20 @@ fn is_unit_expr(expr: &Expr<'_>) -> bool {
15751576
}
15761577

15771578
// Checks if arm has the form `None => None`
1578-
fn is_none_arm(arm: &Arm<'_>) -> bool {
1579-
matches!(arm.pat.kind, PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE))
1579+
fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
1580+
matches!(arm.pat.kind, PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone))
15801581
}
15811582

15821583
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
1583-
fn is_ref_some_arm(arm: &Arm<'_>) -> Option<BindingAnnotation> {
1584+
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<BindingAnnotation> {
15841585
if_chain! {
1585-
if let PatKind::TupleStruct(ref path, pats, _) = arm.pat.kind;
1586-
if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
1586+
if let PatKind::TupleStruct(ref qpath, pats, _) = arm.pat.kind;
1587+
if is_lang_ctor(cx, qpath, OptionSome);
15871588
if let PatKind::Binding(rb, .., ident, _) = pats[0].kind;
15881589
if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
15891590
if let ExprKind::Call(e, args) = remove_blocks(arm.body).kind;
15901591
if let ExprKind::Path(ref some_path) = e.kind;
1591-
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
1592+
if is_lang_ctor(cx, some_path, OptionSome) && args.len() == 1;
15921593
if let ExprKind::Path(QPath::Resolved(_, path2)) = args[0].kind;
15931594
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
15941595
then {
@@ -1700,10 +1701,11 @@ mod redundant_pattern_match {
17001701
use super::REDUNDANT_PATTERN_MATCHING;
17011702
use clippy_utils::diagnostics::span_lint_and_then;
17021703
use clippy_utils::source::snippet;
1703-
use clippy_utils::{is_trait_method, match_qpath, paths};
1704+
use clippy_utils::{is_lang_ctor, is_trait_method, match_qpath, paths};
17041705
use if_chain::if_chain;
17051706
use rustc_ast::ast::LitKind;
17061707
use rustc_errors::Applicability;
1708+
use rustc_hir::LangItem::{OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
17071709
use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind, QPath};
17081710
use rustc_lint::LateContext;
17091711
use rustc_span::sym;
@@ -1735,13 +1737,13 @@ mod redundant_pattern_match {
17351737
let good_method = match kind {
17361738
PatKind::TupleStruct(ref path, patterns, _) if patterns.len() == 1 => {
17371739
if let PatKind::Wild = patterns[0].kind {
1738-
if match_qpath(path, &paths::RESULT_OK) {
1740+
if is_lang_ctor(cx, path, ResultOk) {
17391741
"is_ok()"
1740-
} else if match_qpath(path, &paths::RESULT_ERR) {
1742+
} else if is_lang_ctor(cx, path, ResultErr) {
17411743
"is_err()"
1742-
} else if match_qpath(path, &paths::OPTION_SOME) {
1744+
} else if is_lang_ctor(cx, path, OptionSome) {
17431745
"is_some()"
1744-
} else if match_qpath(path, &paths::POLL_READY) {
1746+
} else if is_lang_ctor(cx, path, PollReady) {
17451747
"is_ready()"
17461748
} else if match_qpath(path, &paths::IPADDR_V4) {
17471749
"is_ipv4()"
@@ -1755,9 +1757,9 @@ mod redundant_pattern_match {
17551757
}
17561758
},
17571759
PatKind::Path(ref path) => {
1758-
if match_qpath(path, &paths::OPTION_NONE) {
1760+
if is_lang_ctor(cx, path, OptionNone) {
17591761
"is_none()"
1760-
} else if match_qpath(path, &paths::POLL_PENDING) {
1762+
} else if is_lang_ctor(cx, path, PollPending) {
17611763
"is_pending()"
17621764
} else {
17631765
return;

0 commit comments

Comments
 (0)