2015-08-05 13:10:45 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
#[deny(string_add)]
|
|
|
|
#[allow(string_add_assign)]
|
|
|
|
fn add_only() { // ignores assignment distinction
|
2015-08-25 16:38:08 +00:00
|
|
|
let mut x = "".to_owned();
|
2015-08-12 14:42:42 +00:00
|
|
|
|
2015-10-11 21:12:21 +00:00
|
|
|
for _ in 1..3 {
|
2015-08-12 19:39:42 +00:00
|
|
|
x = x + "."; //~ERROR you added something to a string.
|
2015-08-12 14:42:42 +00:00
|
|
|
}
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
let y = "".to_owned();
|
2015-08-12 19:39:42 +00:00
|
|
|
let z = y + "..."; //~ERROR you added something to a string.
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(string_add_assign)]
|
|
|
|
fn add_assign_only() {
|
2015-08-25 16:38:08 +00:00
|
|
|
let mut x = "".to_owned();
|
2015-08-12 14:42:42 +00:00
|
|
|
|
2015-10-11 21:12:21 +00:00
|
|
|
for _ in 1..3 {
|
2015-08-12 19:39:42 +00:00
|
|
|
x = x + "."; //~ERROR you assigned the result of adding something to this string.
|
2015-08-12 14:42:42 +00:00
|
|
|
}
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(string_add, string_add_assign)]
|
|
|
|
fn both() {
|
2015-08-12 13:50:56 +00:00
|
|
|
let mut x = "".to_owned();
|
2015-08-11 18:22:20 +00:00
|
|
|
|
2015-10-11 21:12:21 +00:00
|
|
|
for _ in 1..3 {
|
2015-08-12 19:39:42 +00:00
|
|
|
x = x + "."; //~ERROR you assigned the result of adding something to this string.
|
2015-08-11 18:22:20 +00:00
|
|
|
}
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 13:50:56 +00:00
|
|
|
let y = "".to_owned();
|
2015-08-12 19:39:42 +00:00
|
|
|
let z = y + "..."; //~ERROR you added something to a string.
|
2015-08-25 16:38:08 +00:00
|
|
|
|
2015-08-12 13:50:56 +00:00
|
|
|
assert_eq!(&x, &z);
|
2015-08-05 13:10:45 +00:00
|
|
|
}
|
2015-08-12 14:42:42 +00:00
|
|
|
|
2016-01-19 18:14:49 +00:00
|
|
|
#[allow(dead_code, unused_variables)]
|
|
|
|
#[deny(string_lit_as_bytes)]
|
|
|
|
fn str_lit_as_bytes() {
|
2016-03-14 21:03:30 +00:00
|
|
|
let bs = "hello there".as_bytes();
|
|
|
|
//~^ERROR calling `as_bytes()`
|
|
|
|
//~|HELP byte string literal
|
|
|
|
//~|SUGGESTION b"hello there"
|
|
|
|
|
2016-01-19 18:14:49 +00:00
|
|
|
// no warning, because this cannot be written as a byte string literal:
|
|
|
|
let ubs = "☃".as_bytes();
|
2016-03-14 21:03:30 +00:00
|
|
|
|
|
|
|
let strify = stringify!(foobar).as_bytes();
|
2016-01-19 18:14:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 14:42:42 +00:00
|
|
|
fn main() {
|
2015-08-25 16:38:08 +00:00
|
|
|
add_only();
|
|
|
|
add_assign_only();
|
|
|
|
both();
|
|
|
|
|
2016-06-07 16:33:11 +00:00
|
|
|
// the add is only caught for `String`
|
2015-08-25 16:38:08 +00:00
|
|
|
let mut x = 1;
|
2016-06-07 16:33:11 +00:00
|
|
|
; x = x + 1;
|
|
|
|
//~^ WARN assign_op_pattern
|
|
|
|
//~| HELP replace
|
|
|
|
//~| SUGGESTION ; x += 1;
|
2015-08-25 16:38:08 +00:00
|
|
|
assert_eq!(2, x);
|
2015-08-12 14:42:42 +00:00
|
|
|
}
|