|
1 | 1 | use clippy_utils::diagnostics::span_lint_hir_and_then;
|
2 | 2 | use clippy_utils::source::{SpanRangeExt, snippet};
|
| 3 | +use clippy_utils::ty::is_type_diagnostic_item; |
3 | 4 | use clippy_utils::{expr_or_init, is_trait_method, pat_is_wild};
|
4 | 5 | use rustc_errors::Applicability;
|
5 | 6 | use rustc_hir::{Expr, ExprKind, FnDecl, PatKind, TyKind};
|
6 | 7 | use rustc_lint::LateContext;
|
7 |
| -use rustc_middle::ty::AdtDef; |
8 | 8 | use rustc_span::{Span, sym};
|
9 | 9 |
|
10 | 10 | use crate::loops::UNUSED_ENUMERATE_INDEX;
|
@@ -39,9 +39,8 @@ use crate::loops::UNUSED_ENUMERATE_INDEX;
|
39 | 39 | /// * `closure_arg`: The argument to the map function call containing the closure/function to apply
|
40 | 40 | pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>) {
|
41 | 41 | let recv_ty = cx.typeck_results().expr_ty(recv);
|
42 |
| - if let Some(recv_ty_defid) = recv_ty.ty_adt_def().map(AdtDef::did) |
43 |
| - // If we call a method on a `std::iter::Enumerate` instance |
44 |
| - && cx.tcx.is_diagnostic_item(sym::Enumerate, recv_ty_defid) |
| 42 | + // If we call a method on a `std::iter::Enumerate` instance |
| 43 | + if is_type_diagnostic_item(cx, recv_ty, sym::Enumerate) |
45 | 44 | // If we are calling a method of the `Iterator` trait
|
46 | 45 | && is_trait_method(cx, call_expr, sym::Iterator)
|
47 | 46 | // And the map argument is a closure
|
|
0 commit comments