File tree 7 files changed +115
-111
lines changed
7 files changed +115
-111
lines changed Original file line number Diff line number Diff line change
1
+ #[ warn( clippy:: string_add) ]
2
+ #[ allow( clippy:: string_add_assign, unused) ]
3
+ fn main ( ) {
4
+ // ignores assignment distinction
5
+ let mut x = "" . to_owned ( ) ;
6
+
7
+ for _ in 1 ..3 {
8
+ x = x + "." ;
9
+ }
10
+
11
+ let y = "" . to_owned ( ) ;
12
+ let z = y + "..." ;
13
+
14
+ assert_eq ! ( & x, & z) ;
15
+
16
+ let mut x = 1 ;
17
+ x = x + 1 ;
18
+ assert_eq ! ( 2 , x) ;
19
+ }
Original file line number Diff line number Diff line change
1
+ error: manual implementation of an assign operation
2
+ --> $DIR/string_add.rs:8:9
3
+ |
4
+ LL | x = x + ".";
5
+ | ^^^^^^^^^^^ help: replace it with: `x += "."`
6
+ |
7
+ = note: `-D clippy::assign-op-pattern` implied by `-D warnings`
8
+
9
+ error: you added something to a string. Consider using `String::push_str()` instead
10
+ --> $DIR/string_add.rs:8:13
11
+ |
12
+ LL | x = x + ".";
13
+ | ^^^^^^^
14
+ |
15
+ = note: `-D clippy::string-add` implied by `-D warnings`
16
+
17
+ error: you added something to a string. Consider using `String::push_str()` instead
18
+ --> $DIR/string_add.rs:12:13
19
+ |
20
+ LL | let z = y + "...";
21
+ | ^^^^^^^^^
22
+
23
+ error: manual implementation of an assign operation
24
+ --> $DIR/string_add.rs:17:5
25
+ |
26
+ LL | x = x + 1;
27
+ | ^^^^^^^^^ help: replace it with: `x += 1`
28
+
29
+ error: aborting due to 4 previous errors
30
+
Original file line number Diff line number Diff line change
1
+ // run-rustfix
2
+
3
+ #[allow(clippy::string_add, unused)]
4
+ #[warn(clippy::string_add_assign)]
5
+ fn main() {
6
+ // ignores assignment distinction
7
+ let mut x = "".to_owned();
8
+
9
+ for _ in 1..3 {
10
+ x += ".";
11
+ }
12
+
13
+ let y = "".to_owned();
14
+ let z = y + "...";
15
+
16
+ assert_eq!(&x, &z);
17
+
18
+ let mut x = 1;
19
+ x += 1;
20
+ assert_eq!(2, x);
21
+ }
Original file line number Diff line number Diff line change
1
+ // run-rustfix
2
+
3
+ #[ allow( clippy:: string_add, unused) ]
4
+ #[ warn( clippy:: string_add_assign) ]
5
+ fn main ( ) {
6
+ // ignores assignment distinction
7
+ let mut x = "" . to_owned ( ) ;
8
+
9
+ for _ in 1 ..3 {
10
+ x = x + "." ;
11
+ }
12
+
13
+ let y = "" . to_owned ( ) ;
14
+ let z = y + "..." ;
15
+
16
+ assert_eq ! ( & x, & z) ;
17
+
18
+ let mut x = 1 ;
19
+ x = x + 1 ;
20
+ assert_eq ! ( 2 , x) ;
21
+ }
Original file line number Diff line number Diff line change
1
+ error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead
2
+ --> $DIR/string_add_assign.rs:10:9
3
+ |
4
+ LL | x = x + ".";
5
+ | ^^^^^^^^^^^
6
+ |
7
+ = note: `-D clippy::string-add-assign` implied by `-D warnings`
8
+
9
+ error: manual implementation of an assign operation
10
+ --> $DIR/string_add_assign.rs:10:9
11
+ |
12
+ LL | x = x + ".";
13
+ | ^^^^^^^^^^^ help: replace it with: `x += "."`
14
+ |
15
+ = note: `-D clippy::assign-op-pattern` implied by `-D warnings`
16
+
17
+ error: manual implementation of an assign operation
18
+ --> $DIR/string_add_assign.rs:19:5
19
+ |
20
+ LL | x = x + 1;
21
+ | ^^^^^^^^^ help: replace it with: `x += 1`
22
+
23
+ error: aborting due to 3 previous errors
24
+
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments