rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Warn when calling `is_empty` on non-empty value

Open FineFindus opened this issue 4 months ago • 1 comments

What it does

Check if the value that is_empty is called on is immutable and set to a non-empty value (e.g. a string literal), in which case it warns that the code will always evaluate to false. Of course, the opposite could be checked for values that are always set as empty.

Advantage

  • Removing unreachable code

Drawbacks

No response

Example

let value = "Non-empty string";
if value.is_empty() {
   // this is will never execute, since value is always non-empty
   println!("value is empty");
}

Could be written as:

let value = "Non-empty string";

FineFindus avatar Feb 17 '24 21:02 FineFindus

@rustbot claim

samueltardieu avatar Feb 18 '24 14:02 samueltardieu