File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 1
1
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg} ;
2
- use clippy_utils:: is_trait_method;
3
2
use clippy_utils:: source:: snippet;
3
+ use clippy_utils:: ty:: implements_trait;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir as hir;
6
6
use rustc_lint:: LateContext ;
@@ -16,7 +16,10 @@ pub(super) fn check<'tcx>(
16
16
filter_arg : & ' tcx hir:: Expr < ' _ > ,
17
17
) {
18
18
// 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 {
20
23
let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
21
24
`.find(..)` instead";
22
25
let filter_snippet = snippet ( cx, filter_arg. span , ".." ) ;
You can’t perform that action at this time.
0 commit comments