Skip to content

Commit

Permalink
string_add, string_add_assign: split tests, make one rustfixable
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 25, 2019
1 parent 898e971 commit 895c661
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 111 deletions.
19 changes: 19 additions & 0 deletions tests/ui/string_add.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions tests/ui/string_add.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions tests/ui/string_add_assign.fixed
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions tests/ui/string_add_assign.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions tests/ui/string_add_assign.stderr
Original file line number Diff line number Diff line change
@@ -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

55 changes: 0 additions & 55 deletions tests/ui/strings.rs

This file was deleted.

56 changes: 0 additions & 56 deletions tests/ui/strings.stderr

This file was deleted.

0 comments on commit 895c661

Please sign in to comment.