]>
Commit | Line | Data |
---|---|---|
cdc7bbd5 XL |
1 | use clippy_utils::diagnostics::span_lint_and_help; |
2 | use clippy_utils::is_trait_method; | |
f20569fa XL |
3 | use rustc_hir as hir; |
4 | use rustc_lint::LateContext; | |
cdc7bbd5 | 5 | use rustc_span::sym; |
f20569fa XL |
6 | |
7 | use super::SKIP_WHILE_NEXT; | |
8 | ||
9 | /// lint use of `skip_while().next()` for `Iterators` | |
cdc7bbd5 | 10 | pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { |
f20569fa | 11 | // lint if caller of `.skip_while().next()` is an Iterator |
cdc7bbd5 | 12 | if is_trait_method(cx, expr, sym::Iterator) { |
f20569fa XL |
13 | span_lint_and_help( |
14 | cx, | |
15 | SKIP_WHILE_NEXT, | |
16 | expr.span, | |
17 | "called `skip_while(<p>).next()` on an `Iterator`", | |
18 | None, | |
19 | "this is more succinctly expressed by calling `.find(!<p>)` instead", | |
20 | ); | |
21 | } | |
22 | } |