2022-01-13 06:18:19 -06:00
|
|
|
struct Length(u8);
|
|
|
|
struct Meter;
|
|
|
|
|
|
|
|
impl core::ops::Mul<Meter> for u8 {
|
|
|
|
type Output = Length;
|
|
|
|
fn mul(self, _: Meter) -> Length {
|
|
|
|
Length(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Default, PartialEq, Eq, Hash)]
|
|
|
|
struct Vec1 {
|
|
|
|
x: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl core::ops::Mul<Vec1> for i32 {
|
|
|
|
type Output = Vec1;
|
|
|
|
fn mul(self, mut right: Vec1) -> Vec1 {
|
|
|
|
right.x *= self;
|
|
|
|
right
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl core::ops::Mul<i32> for Vec1 {
|
|
|
|
type Output = Vec1;
|
|
|
|
fn mul(mut self, right: i32) -> Vec1 {
|
|
|
|
self.x *= right;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#[allow(clippy::no_effect)]
|
|
|
|
#[warn(clippy::erasing_op)]
|
2023-03-07 11:51:48 -06:00
|
|
|
fn test(x: u8) {
|
2017-09-30 12:14:00 -05:00
|
|
|
x * 0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this operation will always return zero. This is likely not the intended ou
|
|
|
|
//~| NOTE: `-D clippy::erasing-op` implied by `-D warnings`
|
2017-09-30 12:14:00 -05:00
|
|
|
0 & x;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this operation will always return zero. This is likely not the intended ou
|
2017-09-30 12:14:00 -05:00
|
|
|
0 / x;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this operation will always return zero. This is likely not the intended ou
|
2022-01-13 06:18:19 -06:00
|
|
|
0 * Meter; // no error: Output type is different from the non-zero argument
|
|
|
|
0 * Vec1 { x: 5 };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this operation will always return zero. This is likely not the intended ou
|
2022-01-13 06:18:19 -06:00
|
|
|
Vec1 { x: 5 } * 0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this operation will always return zero. This is likely not the intended ou
|
2017-09-30 12:14:00 -05:00
|
|
|
}
|
2023-03-07 11:51:48 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
test(0)
|
|
|
|
}
|