RS.CLIPPY.COMPARISON_TO_EMPTY
Checking `x == \"\"` or `x == []` (or similar) when `.is_empty()` could be used instead
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: comparison_to_empty. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for comparing to an empty slice such as "" or [],
and suggests using .is_empty() where applicable.
Why is this bad?
Some structures can answer .is_empty() much faster
than checking for equality. So it is good to get into the habit of using
.is_empty(), and having it is cheap.
Besides, it makes the intent clearer than a manual comparison in some contexts.
Example
if s == "" {
..
}
if arr == [] {
..
}
Use instead:
if s.is_empty() {
..
}
if arr.is_empty() {
..
}