about summary refs log tree commit diff
path: root/clippy_lints/src/operators/integer_division.rs
blob: 631d10f4a72e9b14710096f4508a7667e466682f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use clippy_utils::diagnostics::span_lint_and_help;
use rustc_hir as hir;
use rustc_lint::LateContext;

use super::INTEGER_DIVISION;

pub(crate) fn check<'tcx>(
    cx: &LateContext<'tcx>,
    expr: &'tcx hir::Expr<'_>,
    op: hir::BinOpKind,
    left: &'tcx hir::Expr<'_>,
    right: &'tcx hir::Expr<'_>,
) {
    if op == hir::BinOpKind::Div
        && cx.typeck_results().expr_ty(left).is_integral()
        && cx.typeck_results().expr_ty(right).is_integral()
    {
        span_lint_and_help(
            cx,
            INTEGER_DIVISION,
            expr.span,
            "integer division",
            None,
            "division of integers may cause loss of precision. consider using floats",
        );
    }
}