Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comparison_to_empty not triggered if comparing Cow<'a, str> to empty string slice #13861

Open
selfisekai opened this issue Dec 21, 2024 · 0 comments · May be fixed by #13871
Open

comparison_to_empty not triggered if comparing Cow<'a, str> to empty string slice #13861

selfisekai opened this issue Dec 21, 2024 · 0 comments · May be fixed by #13871
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@selfisekai
Copy link

Summary

This is effectively the same comparison, but the lint is not triggered

Lint Name

comparison_to_empty

Reproducer

I tried this code:

#![warn(clippy::comparison_to_empty)]

use std::borrow::Cow;

fn main() {
    let s = Cow::Borrowed("");
    if s == "" {}
}

I expected to see this happen:

warning: comparison to empty slice
 --> src/main.rs:7:8
  |
7 |     if s == "" {}
  |        ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty

Instead, this happened:

Version

rustc 1.83.0 (90b35a623 2024-11-26) (Alpine Linux 1.83.0-r0)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-alpine-linux-musl
release: 1.83.0
LLVM version: 19.1.4
@selfisekai selfisekai added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant