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

case_sensitive_file_extension_comparisons should suggest is_some_and #14357

Open
nyurik opened this issue Mar 6, 2025 · 0 comments · May be fixed by #14358
Open

case_sensitive_file_extension_comparisons should suggest is_some_and #14357

nyurik opened this issue Mar 6, 2025 · 0 comments · May be fixed by #14358
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@nyurik
Copy link
Contributor

nyurik commented Mar 6, 2025

Summary

The clippy::case_sensitive_file_extension_comparisons suggestion should not cause subsequent clippy lint.

Reproducer

I tried this code:

fn foo(v: &str)->bool {
    v.ends_with(".a")
}

fn main() {
    println!("test = {:?}", foo("test.a"));
}

I expected the suggestion to not cause any clippy warnings, but instead, it suggested to replace it with this:

2 ~     std::path::Path::new(v)
3 +         .extension()
4 +         .map_or(false, |ext| ext.eq_ignore_ascii_case("a"))

The suggested code produces this:

  = note: `#[warn(clippy::unnecessary_map_or)]` on by default
help: use is_some_and instead
  |
2 ~     std::path::Path::new(v)
3 +         .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("a"))
  |

Version

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7

Additional Labels

No response

@nyurik nyurik added the C-bug Category: Clippy is not doing the correct thing label Mar 6, 2025
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
Projects
None yet
1 participant