1 use rustc::declare_lint_pass;
3 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4 use rustc_session::declare_tool_lint;
5 use syntax::source_map::Span;
7 use crate::consts::{constant_simple, Constant};
8 use crate::utils::span_lint;
10 declare_clippy_lint! {
11 /// **What it does:** Checks for erasing operations, e.g., `x * 0`.
13 /// **Why is this bad?** The whole expression can be replaced by zero.
14 /// This is most likely not the intended outcome and should probably be
17 /// **Known problems:** None.
28 "using erasing operations, e.g., `x * 0` or `y & 0`"
31 declare_lint_pass!(ErasingOp => [ERASING_OP]);
33 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
34 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
35 if e.span.from_expansion() {
38 if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind {
40 BinOpKind::Mul | BinOpKind::BitAnd => {
41 check(cx, left, e.span);
42 check(cx, right, e.span);
44 BinOpKind::Div => check(cx, left, e.span),
51 fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
52 if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) {
57 "this operation will always return zero. This is likely not the intended outcome",