Skip to content

Warn when calling is_empty on non-empty value #12307

Closed
@FineFindus

Description

@FineFindus

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";

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions