rust-lang / rust-lang/rust-clippy
Lint suggestion: use `Path::is_empty()` instead of manual comparisons
@aljazluci is already working on this.
Since Aug 25, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warn when comparing with Path::new("") and suggest using path.is_empty()
Advantage
- More performant
Drawbacks
- Churn
Example
https://github.com/uutils/coreutils/blob/38ffca87fbd8e30fbfde57591f37ed77673874b6/src/uu/mkdir/src/mkdir.rs#L219 (assuming that uutils started requiring 1.98+)
if path == Path::new("") {
return Ok(());
}
Could be written as:
if path.is_empty() {
return Ok(());
}
Comparison with existing lints
Unlike comparison_to_empty this is a comparison to another object rather than to an empty string or slice, so suggesting a new lint rather than an expansion to that
Additional Context
Grep shows a number of hits in public code bases, and there are probably more that aren't caught by this regex due to using more qualified paths: https://grep.app/search?f.lang=Rust®exp=true&q=%5B%21%3D%5D%3D%5Cs%2BPath%3A%3Anew%5C%28%22%22%5C%29
rust-lang/rust#148494
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.