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 11use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg} ;
2- use clippy_utils:: is_trait_method;
32use clippy_utils:: source:: snippet;
3+ use clippy_utils:: ty:: implements_trait;
44use rustc_errors:: Applicability ;
55use rustc_hir as hir;
66use 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 , ".." ) ;
You can’t perform that action at this time.
0 commit comments