diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/assign_ops2.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/assign_ops2.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/assign_ops2.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/assign_ops2.rs b/src/tools/clippy/tests/ui/assign_ops2.rs new file mode 100644 index 000000000..f6d3a8fa3 --- /dev/null +++ b/src/tools/clippy/tests/ui/assign_ops2.rs @@ -0,0 +1,55 @@ +#[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); +} |