]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | use crate::consts::{constant, Constant}; |
2 | use crate::utils::{match_trait_method, paths, span_lint}; | |
3 | use rustc_hir as hir; | |
4 | use rustc_lint::LateContext; | |
5 | ||
6 | use super::ITERATOR_STEP_BY_ZERO; | |
7 | ||
8 | pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { | |
9 | if match_trait_method(cx, expr, &paths::ITERATOR) { | |
10 | if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), &args[1]) { | |
11 | span_lint( | |
12 | cx, | |
13 | ITERATOR_STEP_BY_ZERO, | |
14 | expr.span, | |
15 | "`Iterator::step_by(0)` will panic at runtime", | |
16 | ); | |
17 | } | |
18 | } | |
19 | } |