2015-05-20 01:52:19 -05:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
struct One;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
impl One {
|
2015-08-12 03:46:49 -05:00
|
|
|
fn len(self: &Self) -> isize { //~ERROR item `One` has a `.len(_: &Self)`
|
2015-08-11 13:22:20 -05:00
|
|
|
1
|
|
|
|
}
|
2015-05-20 01:52:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
trait TraitsToo {
|
2015-08-12 03:46:49 -05:00
|
|
|
fn len(self: &Self) -> isize; //~ERROR trait `TraitsToo` has a `.len(_:
|
2015-05-20 01:52:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TraitsToo for One {
|
2015-08-11 13:22:20 -05:00
|
|
|
fn len(self: &Self) -> isize {
|
|
|
|
0
|
|
|
|
}
|
2015-05-20 01:52:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct HasIsEmpty;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
impl HasIsEmpty {
|
2015-08-11 13:22:20 -05:00
|
|
|
fn len(self: &Self) -> isize {
|
|
|
|
1
|
|
|
|
}
|
2015-06-01 05:49:36 -05:00
|
|
|
|
2015-08-11 13:22:20 -05:00
|
|
|
fn is_empty(self: &Self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2015-06-01 05:49:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Wither;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
trait WithIsEmpty {
|
2015-08-11 13:22:20 -05:00
|
|
|
fn len(self: &Self) -> isize;
|
|
|
|
fn is_empty(self: &Self) -> bool;
|
2015-06-01 05:49:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl WithIsEmpty for Wither {
|
2015-08-11 13:22:20 -05:00
|
|
|
fn len(self: &Self) -> isize {
|
|
|
|
1
|
|
|
|
}
|
2015-06-01 05:49:36 -05:00
|
|
|
|
2015-08-11 13:22:20 -05:00
|
|
|
fn is_empty(self: &Self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2015-06-01 05:49:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct HasWrongIsEmpty;
|
|
|
|
|
|
|
|
#[deny(len_without_is_empty)]
|
|
|
|
impl HasWrongIsEmpty {
|
2015-08-12 03:46:49 -05:00
|
|
|
fn len(self: &Self) -> isize { //~ERROR item `HasWrongIsEmpty` has a `.len(_: &Self)`
|
2015-08-11 13:22:20 -05:00
|
|
|
1
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code, unused)]
|
|
|
|
fn is_empty(self: &Self, x : u32) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2015-05-20 01:52:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deny(len_zero)]
|
|
|
|
fn main() {
|
2015-08-11 13:22:20 -05:00
|
|
|
let x = [1, 2];
|
2016-02-24 13:52:47 -06:00
|
|
|
if x.len() == 0 {
|
|
|
|
//~^ERROR length comparison to zero
|
|
|
|
//~|HELP consider using `is_empty`
|
|
|
|
//~|SUGGESTION x.is_empty()
|
2015-08-11 13:22:20 -05:00
|
|
|
println!("This should not happen!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let y = One;
|
|
|
|
if y.len() == 0 { //no error because One does not have .is_empty()
|
|
|
|
println!("This should not happen either!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let z : &TraitsToo = &y;
|
|
|
|
if z.len() > 0 { //no error, because TraitsToo has no .is_empty() method
|
|
|
|
println!("Nor should this!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let hie = HasIsEmpty;
|
2016-02-24 13:52:47 -06:00
|
|
|
if hie.len() == 0 {
|
|
|
|
//~^ERROR length comparison to zero
|
|
|
|
//~|HELP consider using `is_empty`
|
|
|
|
//~|SUGGESTION hie.is_empty()
|
2015-08-11 13:22:20 -05:00
|
|
|
println!("Or this!");
|
|
|
|
}
|
2016-02-24 13:52:47 -06:00
|
|
|
if hie.len() != 0 {
|
|
|
|
//~^ERROR length comparison to zero
|
|
|
|
//~|HELP consider using `is_empty`
|
|
|
|
//~|SUGGESTION !hie.is_empty()
|
2015-08-12 03:53:14 -05:00
|
|
|
println!("Or this!");
|
|
|
|
}
|
2016-02-24 13:52:47 -06:00
|
|
|
if hie.len() > 0 {
|
|
|
|
//~^ERROR length comparison to zero
|
|
|
|
//~|HELP consider using `is_empty`
|
|
|
|
//~|SUGGESTION !hie.is_empty()
|
2015-08-12 03:53:14 -05:00
|
|
|
println!("Or this!");
|
|
|
|
}
|
2015-08-11 13:22:20 -05:00
|
|
|
assert!(!hie.is_empty());
|
|
|
|
|
|
|
|
let wie : &WithIsEmpty = &Wither;
|
2016-02-24 13:52:47 -06:00
|
|
|
if wie.len() == 0 {
|
|
|
|
//~^ERROR length comparison to zero
|
|
|
|
//~|HELP consider using `is_empty`
|
|
|
|
//~|SUGGESTION wie.is_empty()
|
2015-08-11 13:22:20 -05:00
|
|
|
println!("Or this!");
|
|
|
|
}
|
|
|
|
assert!(!wie.is_empty());
|
|
|
|
|
|
|
|
let hwie = HasWrongIsEmpty;
|
|
|
|
if hwie.len() == 0 { //no error as HasWrongIsEmpty does not have .is_empty()
|
|
|
|
println!("Or this!");
|
|
|
|
}
|
2015-05-20 01:52:19 -05:00
|
|
|
}
|