]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs
Auto merge of #84071 - nagisa:nixos-patching-fix, r=Mark-Simulacrum
[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<'_>, arg: &'tcx hir::Expr<'_>) {
11     if is_trait_method(cx, expr, sym::Iterator) {
12         if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), arg) {
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 }