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

Useless check for chars #14052

Open
xamgore opened this issue Jan 21, 2025 · 2 comments
Open

Useless check for chars #14052

xamgore opened this issue Jan 21, 2025 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@xamgore
Copy link

xamgore commented Jan 21, 2025

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

@xamgore xamgore added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 21, 2025
@alex-semenyuk
Copy link
Member

alex-semenyuk commented Jan 22, 2025

This is performance lint.

Why is this bad?
The eq_ignore_ascii_case method is faster because it does not allocate memory for the new strings, and it is more readable.

@xamgore
Copy link
Author

xamgore commented Jan 22, 2025

How does comparing strings relate to comparing chars? For strings the lint is totally legal, while for chars it's meaningless, isn't it?

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-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants