@@ -9,6 +9,7 @@ mod bit_mask;
99mod double_comparison;
1010mod duration_subsec;
1111mod eq_op;
12+ mod erasing_op;
1213mod misrefactored_assign_op;
1314mod op_ref;
1415mod verbose_bit_mask;
@@ -354,6 +355,28 @@ declare_clippy_lint! {
354355 "taking a reference to satisfy the type constraints on `==`"
355356}
356357
358+ declare_clippy_lint ! {
359+ /// ### What it does
360+ /// Checks for erasing operations, e.g., `x * 0`.
361+ ///
362+ /// ### Why is this bad?
363+ /// The whole expression can be replaced by zero.
364+ /// This is most likely not the intended outcome and should probably be
365+ /// corrected
366+ ///
367+ /// ### Example
368+ /// ```rust
369+ /// let x = 1;
370+ /// 0 / x;
371+ /// 0 * x;
372+ /// x & 0;
373+ /// ```
374+ #[ clippy:: version = "pre 1.29.0" ]
375+ pub ERASING_OP ,
376+ correctness,
377+ "using erasing operations, e.g., `x * 0` or `y & 0`"
378+ }
379+
357380pub struct Operators {
358381 arithmetic_context : arithmetic:: Context ,
359382 verbose_bit_mask_threshold : u64 ,
@@ -371,6 +394,7 @@ impl_lint_pass!(Operators => [
371394 DURATION_SUBSEC ,
372395 EQ_OP ,
373396 OP_REF ,
397+ ERASING_OP ,
374398] ) ;
375399impl Operators {
376400 pub fn new ( verbose_bit_mask_threshold : u64 ) -> Self {
@@ -391,6 +415,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
391415 eq_op:: check ( cx, e, op. node , lhs, rhs) ;
392416 op_ref:: check ( cx, e, op. node , lhs, rhs) ;
393417 }
418+ erasing_op:: check ( cx, e, op. node , lhs, rhs) ;
394419 }
395420 self . arithmetic_context . check_binary ( cx, e, op. node , lhs, rhs) ;
396421 bit_mask:: check ( cx, e, op. node , lhs, rhs) ;
0 commit comments