2015-08-05 08:10:45 -05:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
2015-08-12 09:42:42 -05:00
|
|
|
#[deny(string_add)]
|
|
|
|
#[allow(string_add_assign)]
|
|
|
|
fn add_only() { // ignores assignment distinction
|
2015-08-25 11:38:08 -05:00
|
|
|
let mut x = "".to_owned();
|
2015-08-12 09:42:42 -05:00
|
|
|
|
|
|
|
for _ in (1..3) {
|
2015-08-12 14:39:42 -05:00
|
|
|
x = x + "."; //~ERROR you added something to a string.
|
2015-08-12 09:42:42 -05:00
|
|
|
}
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 09:42:42 -05:00
|
|
|
let y = "".to_owned();
|
2015-08-12 14:39:42 -05:00
|
|
|
let z = y + "..."; //~ERROR you added something to a string.
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 09:42:42 -05:00
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(string_add_assign)]
|
|
|
|
fn add_assign_only() {
|
2015-08-25 11:38:08 -05:00
|
|
|
let mut x = "".to_owned();
|
2015-08-12 09:42:42 -05:00
|
|
|
|
|
|
|
for _ in (1..3) {
|
2015-08-12 14:39:42 -05:00
|
|
|
x = x + "."; //~ERROR you assigned the result of adding something to this string.
|
2015-08-12 09:42:42 -05:00
|
|
|
}
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 09:42:42 -05:00
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 09:42:42 -05:00
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(string_add, string_add_assign)]
|
|
|
|
fn both() {
|
2015-08-12 08:50:56 -05:00
|
|
|
let mut x = "".to_owned();
|
2015-08-11 13:22:20 -05:00
|
|
|
|
2015-08-12 08:50:56 -05:00
|
|
|
for _ in (1..3) {
|
2015-08-12 14:39:42 -05:00
|
|
|
x = x + "."; //~ERROR you assigned the result of adding something to this string.
|
2015-08-11 13:22:20 -05:00
|
|
|
}
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 08:50:56 -05:00
|
|
|
let y = "".to_owned();
|
2015-08-12 14:39:42 -05:00
|
|
|
let z = y + "..."; //~ERROR you added something to a string.
|
2015-08-25 11:38:08 -05:00
|
|
|
|
2015-08-12 08:50:56 -05:00
|
|
|
assert_eq!(&x, &z);
|
2015-08-05 08:10:45 -05:00
|
|
|
}
|
2015-08-12 09:42:42 -05:00
|
|
|
|
|
|
|
fn main() {
|
2015-08-25 11:38:08 -05:00
|
|
|
add_only();
|
|
|
|
add_assign_only();
|
|
|
|
both();
|
|
|
|
|
|
|
|
// the add is only caught for String
|
|
|
|
let mut x = 1;
|
|
|
|
x = x + 1;
|
|
|
|
assert_eq!(2, x);
|
2015-08-12 09:42:42 -05:00
|
|
|
}
|