rust-lang / rust-lang/rust-clippy

Useless check for chars

Open
#14,052 5 comments 0 reactions 0 assignees View on GitHub

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

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.