1 use crate::consts::{constant_simple, Constant};
4 use syntax::codemap::Span;
5 use crate::utils::{in_macro, span_lint};
7 /// **What it does:** Checks for erasing operations, e.g. `x * 0`.
9 /// **Why is this bad?** The whole expression can be replaced by zero.
10 /// This is most likely not the intended outcome and should probably be
13 /// **Known problems:** None.
17 /// 0 / x; 0 * x; x & 0
19 declare_clippy_lint! {
22 "using erasing operations, e.g. `x * 0` or `y & 0`"
25 #[derive(Copy, Clone)]
28 impl LintPass for ErasingOp {
29 fn get_lints(&self) -> LintArray {
30 lint_array!(ERASING_OP)
34 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
35 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
39 if let ExprBinary(ref cmp, ref left, ref right) = e.node {
42 check(cx, left, e.span);
43 check(cx, right, e.span);
45 BiDiv => check(cx, left, e.span),
52 fn check(cx: &LateContext, e: &Expr, span: Span) {
53 if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
59 "this operation will always return zero. This is likely not the intended outcome",