rust-lang / rust-lang/rust-clippy
Useless check for chars
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
to_ascii_lowercase is totally fine.
Lint Name
clippy::manual_ignore_case_cmp
Reproducer
I tried this code:
let x: char = 'a';
if x.to_ascii_lowercase() == 's' { ... }
I saw this happen:
manual case-insensitive ASCII comparison Help: for further information visit https://rust-lang.github.io/rust-clippy/master/index. html#manual_ignore_case_cmp Note: `#[warn(clippy::manual_ignore_case_cmp)]` on by default Help: consider using `.eq_ignore_ascii_case()` instead
let x: char = 'a';
if x.eq_ignore_ascii_case(&'s') { ... }
pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool {
self.to_ascii_lowercase() == other.to_ascii_lowercase()
}
Version
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: aarch64-apple-darwin
release: 1.84.0
LLVM version: 19.1.5
Additional Labels
No response
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.
Research direction
Start with the clippy::manual_ignore_case_cmp lint and the provided char reproducer. Review how the lint handles to_ascii_lowercase() comparisons versus eq_ignore_ascii_case(), then run or add the relevant lint test so the reproducer no longer produces an inappropriate warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100