diff options
| author | Takayuki Nakata <f.seasons017@gmail.com> | 2022-03-29 21:51:37 +0900 |
|---|---|---|
| committer | Takayuki Nakata <f.seasons017@gmail.com> | 2022-03-29 21:51:37 +0900 |
| commit | c22b7b8814e459d985c8ab337d933a4ae4feecea (patch) | |
| tree | 8f8733b97cf68e4786939ca5cff87d334b7ad811 /clippy_lints | |
| parent | 6206086dd5a83477131094b1f0ef61b10e7ced42 (diff) | |
| download | rust-c22b7b8814e459d985c8ab337d933a4ae4feecea.tar.gz rust-c22b7b8814e459d985c8ab337d933a4ae4feecea.zip | |
Fix ICE for `iter_overeager_cloned`
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/methods/iter_overeager_cloned.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index b93f1399eae..54c9ca435a4 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -1,11 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; -use clippy_utils::ty::{get_iterator_item_ty, is_copy}; +use clippy_utils::ty::{get_iterator_item_ty, implements_trait, is_copy}; use itertools::Itertools; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; +use rustc_span::sym; use std::ops::Not; use super::ITER_OVEREAGER_CLONED; @@ -20,9 +21,16 @@ pub(super) fn check<'tcx>( map_arg: &[hir::Expr<'_>], ) { // Check if it's iterator and get type associated with `Item`. - let inner_ty = match get_iterator_item_ty(cx, cx.typeck_results().expr_ty_adjusted(recv)) { - Some(ty) => ty, - _ => return, + let inner_ty = if_chain! { + if let Some(iterator_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator); + let recv_ty = cx.typeck_results().expr_ty(recv); + if implements_trait(cx, recv_ty, iterator_trait_id, &[]); + if let Some(inner_ty) = get_iterator_item_ty(cx, cx.typeck_results().expr_ty_adjusted(recv)); + then { + inner_ty + } else { + return; + } }; match inner_ty.kind() { |
