2017-09-18 10:47:33 +00:00
|
|
|
|
|
|
|
|
2017-02-07 20:05:30 +00:00
|
|
|
|
2017-05-17 12:19:44 +00:00
|
|
|
#[warn(string_add)]
|
2017-02-07 20:05:30 +00:00
|
|
|
#[allow(string_add_assign)]
|
|
|
|
fn add_only() { // ignores assignment distinction
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 13:58:07 +00:00
|
|
|
x = x + ".";
|
2017-02-07 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 13:58:07 +00:00
|
|
|
let z = y + "...";
|
2017-02-07 20:05:30 +00:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:19:44 +00:00
|
|
|
#[warn(string_add_assign)]
|
2017-02-07 20:05:30 +00:00
|
|
|
fn add_assign_only() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 13:58:07 +00:00
|
|
|
x = x + ".";
|
2017-02-07 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:19:44 +00:00
|
|
|
#[warn(string_add, string_add_assign)]
|
2017-02-07 20:05:30 +00:00
|
|
|
fn both() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 13:58:07 +00:00
|
|
|
x = x + ".";
|
2017-02-07 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 13:58:07 +00:00
|
|
|
let z = y + "...";
|
2017-02-07 20:05:30 +00:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code, unused_variables)]
|
2017-05-17 12:19:44 +00:00
|
|
|
#[warn(string_lit_as_bytes)]
|
2017-02-07 20:05:30 +00:00
|
|
|
fn str_lit_as_bytes() {
|
|
|
|
let bs = "hello there".as_bytes();
|
2017-02-08 13:58:07 +00:00
|
|
|
|
2017-02-07 20:05:30 +00:00
|
|
|
// 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);
|
|
|
|
}
|