fix manual_ignore_case_cmp chars iterator cmp - #16962
Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
6155d22 to
f58a16a
Compare
| && args[0].1.is_empty() | ||
| && let [map_arg] = args[1].1 | ||
| && let Some(is_lower) = ascii_case_map_closure(cx, map_arg) | ||
| && cx.typeck_results().expr_ty_adjusted(args[0].0).peel_refs().is_str() |
There was a problem hiding this comment.
You should probably be stricter than that, and check if this is a (possibly multi-level) reference to str. Otherwise, you may end up generating fixes that are incorrect, such as in this (convoluted) example:
struct S;
impl S {
fn eq_ignore_case_cmp(self) {}
}
impl std::ops::Deref for S {
type Target = str;
fn deref(&self) -> &Self::Target {
""
}
}
fn bogus(s: S) -> bool {
s.chars()
.map(|c| c.to_ascii_lowercase())
.cmp(s.chars().map(|c| c.to_ascii_lowercase()))
.is_eq()
}This will suggest s.eq_ignore_ascii_case(s) which won't compile.
|
Reminder, once the PR becomes ready for a review, use |
|
Addressed the review feedback by making the Added a regression case for a custom Verification:
|
Please avoid this LLM generated noise, especially when answering review comments. |
This comment has been minimized.
This comment has been minimized.
31df384 to
3a6e1a8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3a6e1a8 to
11e6336
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
changelog: [
manual_ignore_case_cmp]: detect case-folded.chars()iterators compared withIterator::cmpFixes #16961
Summary
.chars().map(|c| c.to_ascii_lowercase()/to_ascii_uppercase()).cmp(...).is_eq()forms..is_ne()form by suggesting!eq_ignore_ascii_case.to_str().is_some_and(...)closure reproducer.Tests
cargo fmt --check -- clippy_lints/src/manual_ignore_case_cmp.rs tests/ui/manual_ignore_case_cmp.rs clippy_utils/src/sym.rsTESTNAME=manual_ignore_case_cmp cargo uiblessTESTNAME=manual_ignore_case_cmp cargo uitestcargo test --test dogfoodgit diff --check