Rust-clippy: Lint for `is_empty` doesn't show the required negation in the error message

Created on 28 Jul 2019  路  3Comments  路  Source: rust-lang/rust-clippy

fn main() {
    let v = vec![1];
    if v.len() > 0 {        
    }
}

Lints:

| if v.len() > 0 {
| ^^^^^^^^^^^ help: using is_empty is clearer and more explicit: !v.is_empty()

The problem is that if user only reads the first part of the message, they will accidentally flip the condition to v.is_empty(). This is a problem reported in the user forum.

It'd be safer to include negation whenever is_empty is mentioned:

help: using !is_empty is clearer and more explicit

A-suggestion good-first-issue

Most helpful comment

@kornelski Hi, I started working on this and updated the fn check_len() method in len_zero.rs.
In this case, do I need to update testcase?

All 3 comments

@kornelski Hi, I started working on this and updated the fn check_len() method in len_zero.rs.
In this case, do I need to update testcase?

Thanks for working on this!

Yeah, the stderr files in the tests/ui/ directory represent the exact output of the compiler (except some normalizations). So every time you change something on a lint output (like in this case), you also have to change the stderr files.

You don't have to do this by hand, just run sh ./tests/ui/update-all-references.sh after running cargo +master uitest and you should see updated stderr files (git status)


BTW: Don't hesitate to open a WIP PR. Most of the time it is easier to answer questions, when we can see your code. Also travis will check automatically, whether you still have to do something (update tests, format code, fix Clippy / Compiler warnings / errors, ...)

@flip1995 Thanks so much for your comment. I got it.

Was this page helpful?
0 / 5 - 0 ratings