2018-10-06 18:18:06 +02:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
2018-10-11 12:16:22 +02:00
|
|
|
|
2017-09-18 12:47:33 +02:00
|
|
|
|
2016-07-20 15:29:24 +02:00
|
|
|
|
|
|
|
#[allow(unused_assignments)]
|
2018-07-28 17:34:52 +02:00
|
|
|
#[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
|
2016-07-20 15:29:24 +02:00
|
|
|
fn main() {
|
|
|
|
let mut a = 5;
|
2017-02-08 14:58:07 +01: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 14:58:38 +01:00
|
|
|
a *= a * a;
|
2018-01-30 17:45:35 +01:00
|
|
|
a = a * a * a;
|
|
|
|
a = a * 42 * a;
|
|
|
|
a = a * 2 + a;
|
2016-07-20 15:29:24 +02:00
|
|
|
a -= 1 - a;
|
|
|
|
a /= 5 / a;
|
|
|
|
a %= 42 % a;
|
|
|
|
a <<= 6 << a;
|
|
|
|
}
|
2016-12-19 11:13:07 +01: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};
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
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 17:05:16 +02: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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|