2022-10-02 14:13:22 -05:00
|
|
|
#![allow(clippy::uninlined_format_args)]
|
|
|
|
|
2016-07-20 08:29:24 -05:00
|
|
|
#[allow(unused_assignments)]
|
2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
|
2016-07-20 08:29:24 -05:00
|
|
|
fn main() {
|
|
|
|
let mut a = 5;
|
2017-02-08 07:58:07 -06:00
|
|
|
a += a + 1;
|
|
|
|
a += 1 + a;
|
|
|
|
a -= a - 1;
|
|
|
|
a *= a * 99;
|
|
|
|
a *= 42 * a;
|
|
|
|
a /= a / 2;
|
|
|
|
a %= a % 5;
|
|
|
|
a &= a & 1;
|
2018-01-30 07:58:38 -06:00
|
|
|
a *= a * a;
|
2018-01-30 10:45:35 -06:00
|
|
|
a = a * a * a;
|
|
|
|
a = a * 42 * a;
|
|
|
|
a = a * 2 + a;
|
2016-07-20 08:29:24 -05:00
|
|
|
a -= 1 - a;
|
|
|
|
a /= 5 / a;
|
|
|
|
a %= 42 % a;
|
|
|
|
a <<= 6 << a;
|
|
|
|
}
|
2016-12-19 04:13:07 -06:00
|
|
|
|
|
|
|
// check that we don't lint on op assign impls, because that's just the way to impl them
|
|
|
|
|
|
|
|
use std::ops::{Mul, MulAssign};
|
|
|
|
|
2022-05-06 02:10:11 -05:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2016-12-19 04:13:07 -06:00
|
|
|
pub struct Wrap(i64);
|
|
|
|
|
|
|
|
impl Mul<i64> for Wrap {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn mul(self, rhs: i64) -> Self {
|
|
|
|
Wrap(self.0 * rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MulAssign<i64> for Wrap {
|
|
|
|
fn mul_assign(&mut self, rhs: i64) {
|
|
|
|
*self = *self * rhs
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 10:05:16 -05:00
|
|
|
|
|
|
|
fn cow_add_assign() {
|
|
|
|
use std::borrow::Cow;
|
|
|
|
let mut buf = Cow::Owned(String::from("bar"));
|
|
|
|
let cows = Cow::Borrowed("foo");
|
|
|
|
|
|
|
|
// this can be linted
|
|
|
|
buf = buf + cows.clone();
|
|
|
|
|
|
|
|
// this should not as cow<str> Add is not commutative
|
|
|
|
buf = cows + buf;
|
|
|
|
println!("{}", buf);
|
|
|
|
}
|