]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs
Merge commit '0969bc6dde001e01e7e1f58c8ccd7750f8a49ae1' into sync_cg_clif-2021-03-29
[rust.git] / src / tools / clippy / clippy_lints / src / methods / iterator_step_by_zero.rs
1 use crate::consts::{constant, Constant};
2 use clippy_utils::diagnostics::span_lint;
3 use clippy_utils::is_trait_method;
4 use rustc_hir as hir;
5 use rustc_lint::LateContext;
6 use rustc_span::sym;
7
8 use super::ITERATOR_STEP_BY_ZERO;
9
10 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) {
11     if is_trait_method(cx, expr, sym::Iterator) {
12         if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &args[1]) {
13             span_lint(
14                 cx,
15                 ITERATOR_STEP_BY_ZERO,
16                 expr.span,
17                 "`Iterator::step_by(0)` will panic at runtime",
18             );
19         }
20     }
21 }