len_without_is_empty false positive #1740

This commit is contained in:
Tim Nielens 2017-08-28 23:13:56 +02:00
parent 73d87d966d
commit ec79970771
3 changed files with 70 additions and 25 deletions

View file

@ -125,6 +125,16 @@ impl HasWrongIsEmpty {
}
}
pub trait Empty {
fn is_empty(&self) -> bool;
}
pub trait InheritingEmpty: Empty { //must not trigger LEN_WITHOUT_IS_EMPTY
fn len(&self) -> isize;
}
fn main() {
let x = [1, 2];
if x.len() == 0 {

View file

@ -10,7 +10,7 @@ error: item `PubOne` has a public `len` method but no corresponding `is_empty` m
|
= note: `-D len-without-is-empty` implied by `-D warnings`
error: trait `PubTraitsToo` has a `len` method but no `is_empty` method
error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method
--> $DIR/len_zero.rs:55:1
|
55 | / pub trait PubTraitsToo {
@ -43,47 +43,47 @@ error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is
| |_^
error: length comparison to zero
--> $DIR/len_zero.rs:130:8
--> $DIR/len_zero.rs:140:8
|
130 | if x.len() == 0 {
140 | if x.len() == 0 {
| ^^^^^^^^^^^^ help: using `is_empty` is more concise: `x.is_empty()`
|
= note: `-D len-zero` implied by `-D warnings`
error: length comparison to zero
--> $DIR/len_zero.rs:134:8
--> $DIR/len_zero.rs:144:8
|
134 | if "".len() == 0 {
144 | if "".len() == 0 {
| ^^^^^^^^^^^^^ help: using `is_empty` is more concise: `"".is_empty()`
error: length comparison to zero
--> $DIR/len_zero.rs:148:8
--> $DIR/len_zero.rs:158:8
|
148 | if has_is_empty.len() == 0 {
158 | if has_is_empty.len() == 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `has_is_empty.is_empty()`
error: length comparison to zero
--> $DIR/len_zero.rs:151:8
--> $DIR/len_zero.rs:161:8
|
151 | if has_is_empty.len() != 0 {
161 | if has_is_empty.len() != 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `!has_is_empty.is_empty()`
error: length comparison to zero
--> $DIR/len_zero.rs:154:8
--> $DIR/len_zero.rs:164:8
|
154 | if has_is_empty.len() > 0 {
164 | if has_is_empty.len() > 0 {
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `!has_is_empty.is_empty()`
error: length comparison to zero
--> $DIR/len_zero.rs:160:8
--> $DIR/len_zero.rs:170:8
|
160 | if with_is_empty.len() == 0 {
170 | if with_is_empty.len() == 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is more concise: `with_is_empty.is_empty()`
error: length comparison to zero
--> $DIR/len_zero.rs:172:8
--> $DIR/len_zero.rs:182:8
|
172 | if b.len() != 0 {
182 | if b.len() != 0 {
| ^^^^^^^^^^^^ help: using `is_empty` is more concise: `!b.is_empty()`
error: aborting due to 11 previous errors