1 use clippy_utils::consts::{constant_simple, Constant};
2 use clippy_utils::diagnostics::span_lint;
3 use clippy_utils::ty::same_type_and_consts;
5 use rustc_hir::{BinOpKind, Expr};
6 use rustc_lint::LateContext;
7 use rustc_middle::ty::TypeckResults;
11 pub(super) fn check<'tcx>(
12 cx: &LateContext<'tcx>,
16 right: &'tcx Expr<'_>,
18 let tck = cx.typeck_results();
20 BinOpKind::Mul | BinOpKind::BitAnd => {
21 check_op(cx, tck, left, right, e);
22 check_op(cx, tck, right, left, e);
24 BinOpKind::Div => check_op(cx, tck, left, right, e),
29 fn different_types(tck: &TypeckResults<'_>, input: &Expr<'_>, output: &Expr<'_>) -> bool {
30 let input_ty = tck.expr_ty(input).peel_refs();
31 let output_ty = tck.expr_ty(output).peel_refs();
32 !same_type_and_consts(input_ty, output_ty)
36 cx: &LateContext<'tcx>,
37 tck: &TypeckResults<'tcx>,
42 if constant_simple(cx, tck, op) == Some(Constant::Int(0)) {
43 if different_types(tck, other, parent) {
50 "this operation will always return zero. This is likely not the intended outcome",