blob: 22ec8b1ee1ee9ee46a828bf9166552041b2a8190 [file]
use clippy_utils::consts::{FullInt, eval_int};
use clippy_utils::diagnostics::span_lint;
use rustc_hir::{BinOpKind, Expr};
use rustc_lint::LateContext;
use super::MODULO_ONE;
pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, op: BinOpKind, right: &Expr<'_>) {
if op == BinOpKind::Rem {
let msg = match eval_int(cx, right) {
Some(FullInt::S(-1)) => "any number modulo -1 will panic/overflow or result in 0",
Some(FullInt::U(1)) => "any number modulo 1 will be 0",
_ => return,
};
span_lint(cx, MODULO_ONE, expr.span, msg);
}
}