]>
Commit | Line | Data |
---|---|---|
abe05a73 XL |
1 | |
2 | ||
ea8adc8c XL |
3 | |
4 | #[warn(string_add)] | |
5 | #[allow(string_add_assign)] | |
6 | fn add_only() { // 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 | ||
19 | #[warn(string_add_assign)] | |
20 | fn add_assign_only() { | |
21 | let mut x = "".to_owned(); | |
22 | ||
23 | for _ in 1..3 { | |
24 | x = x + "."; | |
25 | } | |
26 | ||
27 | let y = "".to_owned(); | |
28 | let z = y + "..."; | |
29 | ||
30 | assert_eq!(&x, &z); | |
31 | } | |
32 | ||
33 | #[warn(string_add, string_add_assign)] | |
34 | fn both() { | |
35 | let mut x = "".to_owned(); | |
36 | ||
37 | for _ in 1..3 { | |
38 | x = x + "."; | |
39 | } | |
40 | ||
41 | let y = "".to_owned(); | |
42 | let z = y + "..."; | |
43 | ||
44 | assert_eq!(&x, &z); | |
45 | } | |
46 | ||
47 | #[allow(dead_code, unused_variables)] | |
48 | #[warn(string_lit_as_bytes)] | |
49 | fn str_lit_as_bytes() { | |
50 | let bs = "hello there".as_bytes(); | |
51 | ||
52 | // no warning, because this cannot be written as a byte string literal: | |
53 | let ubs = "☃".as_bytes(); | |
54 | ||
55 | let strify = stringify!(foobar).as_bytes(); | |
56 | } | |
57 | ||
58 | fn main() { | |
59 | add_only(); | |
60 | add_assign_only(); | |
61 | both(); | |
62 | ||
63 | // the add is only caught for `String` | |
64 | let mut x = 1; | |
65 | ; x = x + 1; | |
66 | assert_eq!(2, x); | |
67 | } |