2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::string_add)]
|
|
|
|
#[allow(clippy::string_add_assign)]
|
2018-10-05 11:06:05 -05:00
|
|
|
fn add_only() {
|
|
|
|
// ignores assignment distinction
|
2017-02-07 14:05:30 -06:00
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 07:58:07 -06:00
|
|
|
x = x + ".";
|
2017-02-07 14:05:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 07:58:07 -06:00
|
|
|
let z = y + "...";
|
2017-02-07 14:05:30 -06:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::string_add_assign)]
|
2017-02-07 14:05:30 -06:00
|
|
|
fn add_assign_only() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 07:58:07 -06:00
|
|
|
x = x + ".";
|
2017-02-07 14:05:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::string_add, clippy::string_add_assign)]
|
2017-02-07 14:05:30 -06:00
|
|
|
fn both() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 07:58:07 -06:00
|
|
|
x = x + ".";
|
2017-02-07 14:05:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 07:58:07 -06:00
|
|
|
let z = y + "...";
|
2017-02-07 14:05:30 -06:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2018-10-24 10:49:39 -05:00
|
|
|
#[allow(clippy::assign_op_pattern)]
|
2017-02-07 14:05:30 -06:00
|
|
|
fn main() {
|
|
|
|
add_only();
|
|
|
|
add_assign_only();
|
|
|
|
both();
|
|
|
|
|
|
|
|
// the add is only caught for `String`
|
|
|
|
let mut x = 1;
|
2018-10-24 10:49:39 -05:00
|
|
|
x = x + 1;
|
2017-02-07 14:05:30 -06:00
|
|
|
assert_eq!(2, x);
|
|
|
|
}
|