2015-05-20 08:52:19 +02:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
struct One;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
impl One {
|
2015-05-20 09:34:02 +02:00
|
|
|
fn len(self: &Self) -> isize { //~ERROR Item 'One' has a '.len()' method
|
2015-05-20 08:52:19 +02:00
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
trait TraitsToo {
|
2015-05-20 09:34:02 +02:00
|
|
|
fn len(self: &Self) -> isize; //~ERROR Trait 'TraitsToo' has a '.len()' method,
|
2015-05-20 08:52:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TraitsToo for One {
|
|
|
|
fn len(self: &Self) -> isize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
struct HasIsEmpty;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
#[allow(dead_code)]
|
|
|
|
impl HasIsEmpty {
|
|
|
|
fn len(self: &Self) -> isize {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_empty() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(len_zero)]
|
|
|
|
fn main() {
|
|
|
|
let x = [1, 2];
|
2015-05-20 09:34:02 +02:00
|
|
|
if x.len() == 0 { //~ERROR Consider replacing the len comparison
|
2015-05-20 08:52:19 +02:00
|
|
|
println!("This should not happen!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let y = One;
|
2015-06-01 07:40:33 +02:00
|
|
|
if y.len() == 0 { //no error because One does not have .is_empty()
|
2015-05-20 08:52:19 +02:00
|
|
|
println!("This should not happen either!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let z : &TraitsToo = &y;
|
2015-05-20 09:34:02 +02:00
|
|
|
if z.len() > 0 { //~ERROR Consider replacing the len comparison
|
2015-05-20 08:52:19 +02:00
|
|
|
println!("Nor should this!");
|
|
|
|
}
|
|
|
|
}
|