string_add, string_add_assign: split tests, make one rustfixable
This commit is contained in:
parent
1a4dcfca35
commit
363e382f5b
19
tests/ui/string_add.rs
Normal file
19
tests/ui/string_add.rs
Normal file
@ -0,0 +1,19 @@
|
||||
#[warn(clippy::string_add)]
|
||||
#[allow(clippy::string_add_assign, unused)]
|
||||
fn main() {
|
||||
// ignores assignment distinction
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x = x + ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
|
||||
let mut x = 1;
|
||||
x = x + 1;
|
||||
assert_eq!(2, x);
|
||||
}
|
30
tests/ui/string_add.stderr
Normal file
30
tests/ui/string_add.stderr
Normal file
@ -0,0 +1,30 @@
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/string_add.rs:8:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^ help: replace it with: `x += "."`
|
||||
|
|
||||
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
||||
error: you added something to a string. Consider using `String::push_str()` instead
|
||||
--> $DIR/string_add.rs:8:13
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::string-add` implied by `-D warnings`
|
||||
|
||||
error: you added something to a string. Consider using `String::push_str()` instead
|
||||
--> $DIR/string_add.rs:12:13
|
||||
|
|
||||
LL | let z = y + "...";
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/string_add.rs:17:5
|
||||
|
|
||||
LL | x = x + 1;
|
||||
| ^^^^^^^^^ help: replace it with: `x += 1`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
21
tests/ui/string_add_assign.fixed
Normal file
21
tests/ui/string_add_assign.fixed
Normal file
@ -0,0 +1,21 @@
|
||||
// run-rustfix
|
||||
|
||||
#[allow(clippy::string_add, unused)]
|
||||
#[warn(clippy::string_add_assign)]
|
||||
fn main() {
|
||||
// ignores assignment distinction
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x += ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
|
||||
let mut x = 1;
|
||||
x += 1;
|
||||
assert_eq!(2, x);
|
||||
}
|
21
tests/ui/string_add_assign.rs
Normal file
21
tests/ui/string_add_assign.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// run-rustfix
|
||||
|
||||
#[allow(clippy::string_add, unused)]
|
||||
#[warn(clippy::string_add_assign)]
|
||||
fn main() {
|
||||
// ignores assignment distinction
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x = x + ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
|
||||
let mut x = 1;
|
||||
x = x + 1;
|
||||
assert_eq!(2, x);
|
||||
}
|
24
tests/ui/string_add_assign.stderr
Normal file
24
tests/ui/string_add_assign.stderr
Normal file
@ -0,0 +1,24 @@
|
||||
error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
|
||||
--> $DIR/string_add_assign.rs:10:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::string-add-assign` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/string_add_assign.rs:10:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^ help: replace it with: `x += "."`
|
||||
|
|
||||
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/string_add_assign.rs:19:5
|
||||
|
|
||||
LL | x = x + 1;
|
||||
| ^^^^^^^^^ help: replace it with: `x += 1`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
@ -1,55 +0,0 @@
|
||||
#[warn(clippy::string_add)]
|
||||
#[allow(clippy::string_add_assign)]
|
||||
fn add_only() {
|
||||
// ignores assignment distinction
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x = x + ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
}
|
||||
|
||||
#[warn(clippy::string_add_assign)]
|
||||
fn add_assign_only() {
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x = x + ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
}
|
||||
|
||||
#[warn(clippy::string_add, clippy::string_add_assign)]
|
||||
fn both() {
|
||||
let mut x = "".to_owned();
|
||||
|
||||
for _ in 1..3 {
|
||||
x = x + ".";
|
||||
}
|
||||
|
||||
let y = "".to_owned();
|
||||
let z = y + "...";
|
||||
|
||||
assert_eq!(&x, &z);
|
||||
}
|
||||
|
||||
#[allow(clippy::assign_op_pattern)]
|
||||
fn main() {
|
||||
add_only();
|
||||
add_assign_only();
|
||||
both();
|
||||
|
||||
// the add is only caught for `String`
|
||||
let mut x = 1;
|
||||
x = x + 1;
|
||||
assert_eq!(2, x);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/strings.rs:8:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^ help: replace it with: `x += "."`
|
||||
|
|
||||
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
||||
error: you added something to a string. Consider using `String::push_str()` instead
|
||||
--> $DIR/strings.rs:8:13
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::string-add` implied by `-D warnings`
|
||||
|
||||
error: you added something to a string. Consider using `String::push_str()` instead
|
||||
--> $DIR/strings.rs:12:13
|
||||
|
|
||||
LL | let z = y + "...";
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
|
||||
--> $DIR/strings.rs:22:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::string-add-assign` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/strings.rs:22:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^ help: replace it with: `x += "."`
|
||||
|
||||
error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
|
||||
--> $DIR/strings.rs:36:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/strings.rs:36:9
|
||||
|
|
||||
LL | x = x + ".";
|
||||
| ^^^^^^^^^^^ help: replace it with: `x += "."`
|
||||
|
||||
error: you added something to a string. Consider using `String::push_str()` instead
|
||||
--> $DIR/strings.rs:40:13
|
||||
|
|
||||
LL | let z = y + "...";
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user