Lint comparison to empty slice using PartialEq methods
This commit is contained in:
parent
43e3384581
commit
acff511871
4 changed files with 55 additions and 2 deletions
|
|
@ -33,4 +33,12 @@ fn main() {
|
|||
if let [0] = &*s
|
||||
&& s == [0]
|
||||
{}
|
||||
|
||||
// Also lint the `PartialEq` methods
|
||||
let s = String::new();
|
||||
let _ = s.is_empty();
|
||||
let _ = !s.is_empty();
|
||||
let v = vec![0];
|
||||
let _ = v.is_empty();
|
||||
let _ = !v.is_empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,12 @@ fn main() {
|
|||
if let [0] = &*s
|
||||
&& s == [0]
|
||||
{}
|
||||
|
||||
// Also lint the `PartialEq` methods
|
||||
let s = String::new();
|
||||
let _ = s.eq("");
|
||||
let _ = s.ne("");
|
||||
let v = vec![0];
|
||||
let _ = v.eq(&[]);
|
||||
let _ = v.ne(&[]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,5 +55,29 @@ error: comparison to empty slice
|
|||
LL | && s == []
|
||||
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:39:13
|
||||
|
|
||||
LL | let _ = s.eq("");
|
||||
| ^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:40:13
|
||||
|
|
||||
LL | let _ = s.ne("");
|
||||
| ^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:42:13
|
||||
|
|
||||
LL | let _ = v.eq(&[]);
|
||||
| ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()`
|
||||
|
||||
error: comparison to empty slice
|
||||
--> tests/ui/comparison_to_empty.rs:43:13
|
||||
|
|
||||
LL | let _ = v.ne(&[]);
|
||||
| ^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue