Skip to content

Commit 18a7dce

Browse files
committed
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
Add negation to `len_zero` lint to show more explicit message. Fixes #4304 I have updated the `len_zero` to show the required negation in case of like the below case. ``` fn main() { let v = vec![1]; if v.len() > 0 { } } ``` changelog: Clarify suggestion of `len_zero` lint.
2 parents 6e6ee87 + ccc3257 commit 18a7dce

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn check_len(
244244
LEN_ZERO,
245245
span,
246246
&format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }),
247-
"using `is_empty` is clearer and more explicit",
247+
&format!("using `{}is_empty` is clearer and more explicit", op),
248248
format!(
249249
"{}{}.is_empty()",
250250
op,

tests/ui/len_zero.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ error: length comparison to zero
2222
--> $DIR/len_zero.rs:83:8
2323
|
2424
LL | if has_is_empty.len() != 0 {
25-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
25+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
2626

2727
error: length comparison to zero
2828
--> $DIR/len_zero.rs:86:8
2929
|
3030
LL | if has_is_empty.len() > 0 {
31-
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
31+
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
3232

3333
error: length comparison to one
3434
--> $DIR/len_zero.rs:89:8
@@ -40,7 +40,7 @@ error: length comparison to one
4040
--> $DIR/len_zero.rs:92:8
4141
|
4242
LL | if has_is_empty.len() >= 1 {
43-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
43+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
4444

4545
error: length comparison to zero
4646
--> $DIR/len_zero.rs:103:8
@@ -52,19 +52,19 @@ error: length comparison to zero
5252
--> $DIR/len_zero.rs:106:8
5353
|
5454
LL | if 0 != has_is_empty.len() {
55-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
5656

5757
error: length comparison to zero
5858
--> $DIR/len_zero.rs:109:8
5959
|
6060
LL | if 0 < has_is_empty.len() {
61-
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
61+
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
6262

6363
error: length comparison to one
6464
--> $DIR/len_zero.rs:112:8
6565
|
6666
LL | if 1 <= has_is_empty.len() {
67-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
67+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
6868

6969
error: length comparison to one
7070
--> $DIR/len_zero.rs:115:8
@@ -82,7 +82,7 @@ error: length comparison to zero
8282
--> $DIR/len_zero.rs:142:8
8383
|
8484
LL | if b.len() != 0 {}
85-
| ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!b.is_empty()`
85+
| ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()`
8686

8787
error: aborting due to 14 previous errors
8888

0 commit comments

Comments
 (0)