rust/tests/ui/assign_ops2.rs
Yuri Astrakhan eb3970285b fallout: fix tests to allow uninlined_format_args
In order to switch `clippy::uninlined_format_args` from pedantic to
style, all existing tests must not raise a warning. I did not want to
change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

changelog: none
2022-10-02 15:13:22 -04:00

58 lines
1.1 KiB
Rust

#![allow(clippy::uninlined_format_args)]
#[allow(unused_assignments)]
#[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
fn main() {
let mut a = 5;
a += a + 1;
a += 1 + a;
a -= a - 1;
a *= a * 99;
a *= 42 * a;
a /= a / 2;
a %= a % 5;
a &= a & 1;
a *= a * a;
a = a * a * a;
a = a * 42 * a;
a = a * 2 + a;
a -= 1 - a;
a /= 5 / a;
a %= 42 % a;
a <<= 6 << a;
}
// check that we don't lint on op assign impls, because that's just the way to impl them
use std::ops::{Mul, MulAssign};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
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
}
}
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);
}