rust-clippy/clippy_lints/src/loops/iter_next_loop.rs
Michael Howell 48268f5237 fix(clippy): update loop lints to use arg.span
Adapts clippy for fe1a7f71fbf3cf845a09a9b333a6adcf7e839607
2021-09-06 23:30:04 -07:00

21 lines
580 B
Rust

use super::ITER_NEXT_LOOP;
use clippy_utils::diagnostics::span_lint;
use clippy_utils::is_trait_method;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_span::sym;
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
if is_trait_method(cx, arg, sym::Iterator) {
span_lint(
cx,
ITER_NEXT_LOOP,
arg.span,
"you are iterating over `Iterator::next()` which is an Option; this will compile but is \
probably not what you want",
);
true
} else {
false
}
}