1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![feature(plugin)]
#![plugin(clippy)]
#[deny(string_add)]
#[allow(string_add_assign)]
fn add_only() { // ignores assignment distinction
let mut x = "".to_owned();
for _ in 1..3 {
x = x + "."; //~ERROR you added something to a string.
}
let y = "".to_owned();
let z = y + "..."; //~ERROR you added something to a string.
assert_eq!(&x, &z);
}
#[deny(string_add_assign)]
fn add_assign_only() {
let mut x = "".to_owned();
for _ in 1..3 {
x = x + "."; //~ERROR you assigned the result of adding something to this string.
}
let y = "".to_owned();
let z = y + "...";
assert_eq!(&x, &z);
}
#[deny(string_add, string_add_assign)]
fn both() {
let mut x = "".to_owned();
for _ in 1..3 {
x = x + "."; //~ERROR you assigned the result of adding something to this string.
}
let y = "".to_owned();
let z = y + "..."; //~ERROR you added something to a string.
assert_eq!(&x, &z);
}
#[allow(dead_code, unused_variables)]
#[deny(string_lit_as_bytes)]
fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();
//~^ERROR calling `as_bytes()`
//~|HELP byte string literal
//~|SUGGESTION b"hello there"
// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();
let strify = stringify!(foobar).as_bytes();
}
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);
}