]> git.lizzy.rs Git - rust.git/blob - tests/ui/strings.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / strings.rs
1 #[warn(clippy::string_add)]
2 #[allow(clippy::string_add_assign)]
3 fn add_only() {
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
17 #[warn(clippy::string_add_assign)]
18 fn add_assign_only() {
19     let mut x = "".to_owned();
20
21     for _ in 1..3 {
22         x = x + ".";
23     }
24
25     let y = "".to_owned();
26     let z = y + "...";
27
28     assert_eq!(&x, &z);
29 }
30
31 #[warn(clippy::string_add, clippy::string_add_assign)]
32 fn both() {
33     let mut x = "".to_owned();
34
35     for _ in 1..3 {
36         x = x + ".";
37     }
38
39     let y = "".to_owned();
40     let z = y + "...";
41
42     assert_eq!(&x, &z);
43 }
44
45 #[allow(clippy::assign_op_pattern)]
46 fn main() {
47     add_only();
48     add_assign_only();
49     both();
50
51     // the add is only caught for `String`
52     let mut x = 1;
53     x = x + 1;
54     assert_eq!(2, x);
55 }