rust/clippy_lints/src/methods/skip_while_next.rs

23 lines
754 B
Rust
Raw Normal View History

use crate::utils::is_trait_method;
use clippy_utils::diagnostics::span_lint_and_help;
2021-03-02 09:31:15 -06:00
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::sym;
2021-03-02 09:31:15 -06:00
use super::SKIP_WHILE_NEXT;
/// lint use of `skip_while().next()` for `Iterators`
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _skip_while_args: &'tcx [hir::Expr<'_>]) {
// lint if caller of `.skip_while().next()` is an Iterator
if is_trait_method(cx, expr, sym::Iterator) {
2021-03-02 09:31:15 -06:00
span_lint_and_help(
cx,
SKIP_WHILE_NEXT,
expr.span,
"called `skip_while(<p>).next()` on an `Iterator`",
None,
"this is more succinctly expressed by calling `.find(!<p>)` instead",
);
}
}