rust-lang / rust-lang/rust-clippy

Lint suggestion: use `Path::is_empty()` instead of manual comparisons

Open
#17,615 1 comment 0 reactions 1 assignee View on GitHub

@aljazluci is already working on this.

Since Aug 25, 2026.

A-lint
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&regexp=true&q=%5B%21%3D%5D%3D%5Cs%2BPath%3A%3Anew%5C%28%22%22%5C%29

rust-lang/rust#148494

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.