@@ -8,6 +8,7 @@ mod bit_mask;
88mod double_comparison;
99mod duration_subsec;
1010mod eq_op;
11+ mod erasing_op;
1112mod misrefactored_assign_op;
1213mod numeric_arithmetic;
1314mod op_ref;
@@ -360,6 +361,28 @@ declare_clippy_lint! {
360361 "taking a reference to satisfy the type constraints on `==`"
361362}
362363
364+ declare_clippy_lint ! {
365+ /// ### What it does
366+ /// Checks for erasing operations, e.g., `x * 0`.
367+ ///
368+ /// ### Why is this bad?
369+ /// The whole expression can be replaced by zero.
370+ /// This is most likely not the intended outcome and should probably be
371+ /// corrected
372+ ///
373+ /// ### Example
374+ /// ```rust
375+ /// let x = 1;
376+ /// 0 / x;
377+ /// 0 * x;
378+ /// x & 0;
379+ /// ```
380+ #[ clippy:: version = "pre 1.29.0" ]
381+ pub ERASING_OP ,
382+ correctness,
383+ "using erasing operations, e.g., `x * 0` or `y & 0`"
384+ }
385+
363386pub struct Operators {
364387 arithmetic_context : numeric_arithmetic:: Context ,
365388 verbose_bit_mask_threshold : u64 ,
@@ -377,6 +400,7 @@ impl_lint_pass!(Operators => [
377400 DURATION_SUBSEC ,
378401 EQ_OP ,
379402 OP_REF ,
403+ ERASING_OP ,
380404] ) ;
381405impl Operators {
382406 pub fn new ( verbose_bit_mask_threshold : u64 ) -> Self {
@@ -397,6 +421,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
397421 eq_op:: check ( cx, e, op. node , lhs, rhs) ;
398422 op_ref:: check ( cx, e, op. node , lhs, rhs) ;
399423 }
424+ erasing_op:: check ( cx, e, op. node , lhs, rhs) ;
400425 }
401426 self . arithmetic_context . check_binary ( cx, e, op. node , lhs, rhs) ;
402427 bit_mask:: check ( cx, e, op. node , lhs, rhs) ;
0 commit comments