Skip to content

Commit 83874d0

Browse files
committed
Make use of Option/Result diagnostic items
1 parent 79982a2 commit 83874d0

14 files changed

+45
-55
lines changed

clippy_lints/src/booleans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, in_macro, match_type, paths, snippet_opt, span_lint_and_sugg,
2+
get_trait_def_id, is_type_diagnostic_item, implements_trait, in_macro, paths, snippet_opt, span_lint_and_sugg,
33
span_lint_and_then, SpanlessEq,
44
};
55
use if_chain::if_chain;
@@ -249,7 +249,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
249249
},
250250
ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
251251
let type_of_receiver = cx.tables.expr_ty(&args[0]);
252-
if !match_type(cx, type_of_receiver, &paths::OPTION) && !match_type(cx, type_of_receiver, &paths::RESULT) {
252+
if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type)) && !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type)) {
253253
return None;
254254
}
255255
METHODS_WITH_NEGATION

clippy_lints/src/cognitive_complexity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::source_map::Span;
1010
use rustc_span::BytePos;
1111

12-
use crate::utils::{match_type, paths, snippet_opt, span_lint_and_help, LimitStack};
12+
use crate::utils::{snippet_opt, span_lint_and_help, LimitStack, is_type_diagnostic_item};
1313

1414
declare_clippy_lint! {
1515
/// **What it does:** Checks for methods with high cognitive complexity.
@@ -61,7 +61,7 @@ impl CognitiveComplexity {
6161
helper.visit_expr(expr);
6262
let CCHelper { cc, returns } = helper;
6363
let ret_ty = cx.tables.node_type(expr.hir_id);
64-
let ret_adjust = if match_type(cx, ret_ty, &paths::RESULT) {
64+
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) {
6565
returns
6666
} else {
6767
#[allow(clippy::integer_division)]

clippy_lints/src/doc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
1+
use crate::utils::{implements_trait, is_entrypoint_fn, is_type_diagnostic_item, return_ty, span_lint};
22
use if_chain::if_chain;
33
use itertools::Itertools;
44
use rustc_ast::ast::{AttrKind, Attribute};
@@ -217,7 +217,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
217217
);
218218
}
219219
if !headers.errors {
220-
if match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
220+
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym!(result_type)) {
221221
span_lint(
222222
cx,
223223
MISSING_ERRORS_DOC,
@@ -235,7 +235,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
235235
if let ty::Opaque(_, subs) = ret_ty.kind;
236236
if let Some(gen) = subs.types().next();
237237
if let ty::Generator(_, subs, _) = gen.kind;
238-
if match_type(cx, subs.as_generator().return_ty(), &paths::RESULT);
238+
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym!(result_type));
239239
then {
240240
span_lint(
241241
cx,

clippy_lints/src/fallible_impl_from.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT};
2-
use crate::utils::{is_expn_of, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty};
1+
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT};
2+
use crate::utils::{is_expn_of, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_type_diagnostic_item};
33
use if_chain::if_chain;
44
use rustc_hir as hir;
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::hir::map::Map;
7-
use rustc_middle::ty::{self, Ty};
7+
use rustc_middle::ty;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::Span;
1010

@@ -76,7 +76,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
7676
// check for `unwrap`
7777
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
7878
let reciever_ty = walk_ptrs_ty(self.tables.expr_ty(&arglists[0][0]));
79-
if match_type(self.lcx, reciever_ty, &OPTION) || match_type(self.lcx, reciever_ty, &RESULT) {
79+
if is_type_diagnostic_item(self.lcx, reciever_ty, sym!(option_type)) || is_type_diagnostic_item(self.lcx, reciever_ty, sym!(result_type)) {
8080
self.result.push(expr.span);
8181
}
8282
}
@@ -124,10 +124,3 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
124124
}
125125
}
126126
}
127-
128-
fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool {
129-
match ty.kind {
130-
ty::Adt(adt, _) => match_def_path(cx, adt.did, path),
131-
_ => false,
132-
}
133-
}

clippy_lints/src/if_let_some_result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_type, method_chain_args, paths, snippet_with_applicability, span_lint_and_sugg};
1+
use crate::utils::{is_type_diagnostic_item, method_chain_args, snippet_with_applicability, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Expr, ExprKind, MatchSource, PatKind, QPath};
@@ -45,8 +45,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
4545
if let ExprKind::MethodCall(_, ok_span, ref result_types) = op.kind; //check is expr.ok() has type Result<T,E>.ok()
4646
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
4747
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
48-
let is_result_type = match_type(cx, cx.tables.expr_ty(&result_types[0]), &paths::RESULT);
49-
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some" && is_result_type;
48+
if is_type_diagnostic_item(cx, cx.tables.expr_ty(&result_types[0]), sym!(result_type));
49+
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
5050

5151
then {
5252
let mut applicability = Applicability::MachineApplicable;

clippy_lints/src/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e
13921392
/// Checks for `for` loops over `Option`s and `Result`s.
13931393
fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
13941394
let ty = cx.tables.expr_ty(arg);
1395-
if match_type(cx, ty, &paths::OPTION) {
1395+
if is_type_diagnostic_item(cx, ty, sym!(option_type)) {
13961396
span_lint_and_help(
13971397
cx,
13981398
FOR_LOOP_OVER_OPTION,
@@ -1408,7 +1408,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
14081408
snippet(cx, arg.span, "_")
14091409
),
14101410
);
1411-
} else if match_type(cx, ty, &paths::RESULT) {
1411+
} else if is_type_diagnostic_item(cx, ty, sym!(result_type)) {
14121412
span_lint_and_help(
14131413
cx,
14141414
FOR_LOOP_OVER_RESULT,

clippy_lints/src/map_clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
is_copy, match_trait_method, match_type, remove_blocks, snippet_with_applicability, span_lint_and_sugg,
3+
is_copy, is_type_diagnostic_item, match_trait_method, remove_blocks, snippet_with_applicability, span_lint_and_sugg,
44
};
55
use if_chain::if_chain;
66
use rustc_ast::ast::Ident;
@@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
5252
if args.len() == 2;
5353
if method.ident.as_str() == "map";
5454
let ty = cx.tables.expr_ty(&args[0]);
55-
if match_type(cx, ty, &paths::OPTION) || match_trait_method(cx, e, &paths::ITERATOR);
55+
if is_type_diagnostic_item(cx, ty, sym!(option_type)) || match_trait_method(cx, e, &paths::ITERATOR);
5656
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
5757
let closure_body = cx.tcx.hir().body(body_id);
5858
let closure_expr = remove_blocks(&closure_body.value);

clippy_lints/src/map_unit_fn.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::utils::paths;
2-
use crate::utils::{iter_input_pats, match_type, method_chain_args, snippet, span_lint_and_then};
1+
use crate::utils::{is_type_diagnostic_item, iter_input_pats, method_chain_args, snippet, span_lint_and_then};
32
use if_chain::if_chain;
43
use rustc_errors::Applicability;
54
use rustc_hir as hir;
@@ -206,9 +205,9 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String {
206205
fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) {
207206
let var_arg = &map_args[0];
208207

209-
let (map_type, variant, lint) = if match_type(cx, cx.tables.expr_ty(var_arg), &paths::OPTION) {
208+
let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(option_type)) {
210209
("Option", "Some", OPTION_MAP_UNIT_FN)
211-
} else if match_type(cx, cx.tables.expr_ty(var_arg), &paths::RESULT) {
210+
} else if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(result_type)) {
212211
("Result", "Ok", RESULT_MAP_UNIT_FN)
213212
} else {
214213
return;

clippy_lints/src/matches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::paths;
33
use crate::utils::sugg::Sugg;
44
use crate::utils::usage::is_unused;
55
use crate::utils::{
6-
expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_wild,
6+
expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_type_diagnostic_item, is_wild,
77
match_qpath, match_type, match_var, multispan_sugg, remove_blocks, snippet, snippet_block,
88
snippet_with_applicability, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
99
walk_ptrs_ty,
@@ -642,7 +642,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'
642642

643643
fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
644644
let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex));
645-
if match_type(cx, ex_ty, &paths::RESULT) {
645+
if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) {
646646
for arm in arms {
647647
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
648648
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));

clippy_lints/src/methods/mod.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,9 @@ fn lint_expect_fun_call(
18361836
}
18371837

18381838
let receiver_type = cx.tables.expr_ty_adjusted(&args[0]);
1839-
let closure_args = if match_type(cx, receiver_type, &paths::OPTION) {
1839+
let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym!(option_type)) {
18401840
"||"
1841-
} else if match_type(cx, receiver_type, &paths::RESULT) {
1841+
} else if is_type_diagnostic_item(cx, receiver_type, sym!(result_type)) {
18421842
"|_|"
18431843
} else {
18441844
return;
@@ -2067,7 +2067,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &
20672067
if_chain! {
20682068
let source_type = cx.tables.expr_ty(source);
20692069
if let ty::Adt(def, substs) = source_type.kind;
2070-
if match_def_path(cx, def.did, &paths::RESULT);
2070+
if cx.tcx.is_diagnostic_item(sym!(result_type), def.did);
20712071
if match_type(cx, substs.type_at(0), &paths::CSTRING);
20722072
then {
20732073
span_lint_and_then(
@@ -2395,9 +2395,9 @@ fn derefs_to_slice<'a, 'tcx>(
23952395
fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) {
23962396
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&unwrap_args[0]));
23972397

2398-
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
2398+
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
23992399
Some((OPTION_UNWRAP_USED, "an Option", "None"))
2400-
} else if match_type(cx, obj_ty, &paths::RESULT) {
2400+
} else if is_type_diagnostic_item(cx, obj_ty, sym!(result_type)) {
24012401
Some((RESULT_UNWRAP_USED, "a Result", "Err"))
24022402
} else {
24032403
None
@@ -2422,9 +2422,9 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
24222422
fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) {
24232423
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&expect_args[0]));
24242424

2425-
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
2425+
let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) {
24262426
Some((OPTION_EXPECT_USED, "an Option", "None"))
2427-
} else if match_type(cx, obj_ty, &paths::RESULT) {
2427+
} else if is_type_diagnostic_item(cx, obj_ty, sym!(result_type)) {
24282428
Some((RESULT_EXPECT_USED, "a Result", "Err"))
24292429
} else {
24302430
None
@@ -2445,7 +2445,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
24452445
fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) {
24462446
if_chain! {
24472447
// lint if the caller of `ok()` is a `Result`
2448-
if match_type(cx, cx.tables.expr_ty(&ok_args[0]), &paths::RESULT);
2448+
if is_type_diagnostic_item(cx, cx.tables.expr_ty(&ok_args[0]), sym!(result_type));
24492449
let result_type = cx.tables.expr_ty(&ok_args[0]);
24502450
if let Some(error_type) = get_error_type(cx, result_type);
24512451
if has_debug_impl(error_type, cx);
@@ -2491,8 +2491,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
24912491
unwrap_args: &'tcx [hir::Expr<'_>],
24922492
) {
24932493
// lint if the caller of `map()` is an `Option`
2494-
let is_option = match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION);
2495-
let is_result = match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::RESULT);
2494+
let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type));
2495+
let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(result_type));
24962496

24972497
if is_option || is_result {
24982498
// Don't make a suggestion that may fail to compile due to mutably borrowing
@@ -2559,8 +2559,8 @@ fn lint_map_or_none<'a, 'tcx>(
25592559
expr: &'tcx hir::Expr<'_>,
25602560
map_or_args: &'tcx [hir::Expr<'_>],
25612561
) {
2562-
let is_option = match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION);
2563-
let is_result = match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::RESULT);
2562+
let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(option_type));
2563+
let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(result_type));
25642564

25652565
// There are two variants of this `map_or` lint:
25662566
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
@@ -3210,7 +3210,6 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
32103210
ty::Array(ref component, _) => is_maybe_uninit_ty_valid(cx, component),
32113211
ty::Tuple(ref types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)),
32123212
ty::Adt(ref adt, _) => {
3213-
// needs to be a MaybeUninit
32143213
match_def_path(cx, adt.did, &paths::MEM_MAYBEUNINIT)
32153214
},
32163215
_ => false,
@@ -3326,7 +3325,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
33263325
/// Given a `Result<T, E>` type, return its error type (`E`).
33273326
fn get_error_type<'a>(cx: &LateContext<'_, '_>, ty: Ty<'a>) -> Option<Ty<'a>> {
33283327
match ty.kind {
3329-
ty::Adt(_, substs) if match_type(cx, ty, &paths::RESULT) => substs.types().nth(1),
3328+
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym!(result_type)) => substs.types().nth(1),
33303329
_ => None,
33313330
}
33323331
}

clippy_lints/src/methods/option_map_unwrap_or.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::utils::{differing_macro_contexts, paths, snippet_with_applicability, span_lint_and_then};
2-
use crate::utils::{is_copy, match_type};
1+
use crate::utils::{differing_macro_contexts, snippet_with_applicability, span_lint_and_then};
2+
use crate::utils::{is_copy, is_type_diagnostic_item};
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::Applicability;
55
use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
@@ -20,7 +20,7 @@ pub(super) fn lint<'a, 'tcx>(
2020
map_span: Span,
2121
) {
2222
// lint if the caller of `map()` is an `Option`
23-
if match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION) {
23+
if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) {
2424
if !is_copy(cx, cx.tables.expr_ty(&unwrap_args[1])) {
2525
// Do not lint if the `map` argument uses identifiers in the `map`
2626
// argument that are also used in the `unwrap_or` argument

clippy_lints/src/question_mark.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use rustc_hir::{def, BindingAnnotation, Block, Expr, ExprKind, MatchSource, PatK
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77

8-
use crate::utils::paths::{OPTION, OPTION_NONE};
98
use crate::utils::sugg::Sugg;
109
use crate::utils::{
11-
higher, match_def_path, match_qpath, match_type, snippet_with_applicability, span_lint_and_sugg, SpanlessEq,
10+
higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, span_lint_and_sugg, SpanlessEq,
1211
};
1312

1413
declare_clippy_lint! {
@@ -141,7 +140,7 @@ impl QuestionMark {
141140
fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
142141
let expr_ty = cx.tables.expr_ty(expression);
143142

144-
match_type(cx, expr_ty, &OPTION)
143+
is_type_diagnostic_item(cx, expr_ty, sym!(option_type))
145144
}
146145

147146
fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
@@ -158,7 +157,7 @@ impl QuestionMark {
158157
if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) =
159158
cx.tables.qpath_res(qp, expression.hir_id)
160159
{
161-
return match_def_path(cx, def_id, &OPTION_NONE);
160+
return match_def_path(cx, def_id, &paths::OPTION_NONE);
162161
}
163162

164163
false

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl Types {
420420
return; // don't recurse into the type
421421
}
422422
}
423-
} else if match_def_path(cx, def_id, &paths::OPTION) {
423+
} else if cx.tcx.is_diagnostic_item(sym!(option_type), def_id) {
424424
if match_type_parameter(cx, qpath, &paths::OPTION).is_some() {
425425
span_lint(
426426
cx,

clippy_lints/src/unwrap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
1+
use crate::utils::{higher::if_block, span_lint_and_then, usage::is_potentially_mutated, is_type_diagnostic_item};
22
use if_chain::if_chain;
33
use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
44
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Path, QPath, UnOp};
@@ -100,7 +100,7 @@ fn collect_unwrap_info<'a, 'tcx>(
100100
if let ExprKind::MethodCall(method_name, _, args) = &expr.kind;
101101
if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind;
102102
let ty = cx.tables.expr_ty(&args[0]);
103-
if match_type(cx, ty, &paths::OPTION) || match_type(cx, ty, &paths::RESULT);
103+
if is_type_diagnostic_item(cx, ty, sym!(option_type)) || is_type_diagnostic_item(cx, ty, sym!(result_type));
104104
let name = method_name.ident.as_str();
105105
if ["is_some", "is_none", "is_ok", "is_err"].contains(&&*name);
106106
then {

0 commit comments

Comments
 (0)