diff options
| author | dswij <dswijj@gmail.com> | 2021-08-13 14:36:40 +0800 |
|---|---|---|
| committer | dswij <dswijj@gmail.com> | 2021-08-13 14:56:37 +0800 |
| commit | 91b598a8e484da328325ece3400e8612b6f854df (patch) | |
| tree | 803b1a01a433d91ba66979640e1c254cf151e584 | |
| parent | e9f56f949d2d1c11f1331151323beb8e85181c29 (diff) | |
| download | rust-91b598a8e484da328325ece3400e8612b6f854df.tar.gz rust-91b598a8e484da328325ece3400e8612b6f854df.zip | |
Fix false positive on `filter_next`
| -rw-r--r-- | clippy_lints/src/methods/filter_next.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/filter_next.rs b/clippy_lints/src/methods/filter_next.rs index 172714f6b01..bcf8d93b602 100644 --- a/clippy_lints/src/methods/filter_next.rs +++ b/clippy_lints/src/methods/filter_next.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; -use clippy_utils::is_trait_method; use clippy_utils::source::snippet; +use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -16,7 +16,10 @@ pub(super) fn check<'tcx>( filter_arg: &'tcx hir::Expr<'_>, ) { // lint if caller of `.filter().next()` is an Iterator - if is_trait_method(cx, expr, sym::Iterator) { + let recv_impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| { + implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[]) + }); + if recv_impls_iterator { let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \ `.find(..)` instead"; let filter_snippet = snippet(cx, filter_arg.span, ".."); |
