2021-03-25 13:29:11 -05:00
|
|
|
use clippy_utils::diagnostics::span_lint_and_help;
|
|
|
|
use clippy_utils::is_trait_method;
|
2021-03-12 08:30:50 -06:00
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_lint::LateContext;
|
2021-03-25 13:29:11 -05:00
|
|
|
use rustc_span::sym;
|
2021-03-12 08:30:50 -06:00
|
|
|
|
|
|
|
use super::SKIP_WHILE_NEXT;
|
|
|
|
|
|
|
|
/// lint use of `skip_while().next()` for `Iterators`
|
2021-04-08 10:50:13 -05:00
|
|
|
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
2021-03-12 08:30:50 -06:00
|
|
|
// lint if caller of `.skip_while().next()` is an Iterator
|
2021-03-25 13:29:11 -05:00
|
|
|
if is_trait_method(cx, expr, sym::Iterator) {
|
2021-03-12 08:30:50 -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",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|