Skip to content

Commit 91b598a

Browse files
committed
Fix false positive on filter_next
1 parent e9f56f9 commit 91b598a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clippy_lints/src/methods/filter_next.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
2-
use clippy_utils::is_trait_method;
32
use clippy_utils::source::snippet;
3+
use clippy_utils::ty::implements_trait;
44
use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_lint::LateContext;
@@ -16,7 +16,10 @@ pub(super) fn check<'tcx>(
1616
filter_arg: &'tcx hir::Expr<'_>,
1717
) {
1818
// lint if caller of `.filter().next()` is an Iterator
19-
if is_trait_method(cx, expr, sym::Iterator) {
19+
let recv_impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| {
20+
implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[])
21+
});
22+
if recv_impls_iterator {
2023
let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
2124
`.find(..)` instead";
2225
let filter_snippet = snippet(cx, filter_arg.span, "..");

0 commit comments

Comments
 (0)