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

manual_is_ascii_check suggests incorrect type #13913

Closed
Otto-AA opened this issue Dec 31, 2024 · 0 comments · Fixed by #13916
Closed

manual_is_ascii_check suggests incorrect type #13913

Otto-AA opened this issue Dec 31, 2024 · 0 comments · Fixed by #13916
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Otto-AA
Copy link
Contributor

Otto-AA commented Dec 31, 2024

Summary

The manual_is_ascii_check lint suggests an incompatible type, leading to a compilation error. The lambda requires |c: &char|, but clippy inserts |c: char| instead.

I think this is related to #11988.

Reproducer

I tried this code:

fn main() {
    let digits: String = "1234ABCD"
        .chars()
        .take_while(|c| ('0'..='9').contains(c)) // <-- line that is changed
        .collect();

    println!("{digits}");
}

I expected to see this happen:

  • either .take_while(|c| c.is_ascii_digit())
  • or .take_while(|c: &char| c.is_ascii_digit())

Instead, this happened:

  • .take_while(|c: char| c.is_ascii_digit())

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

@rustbot label I-suggestion-causes-error

@Otto-AA Otto-AA added the C-bug Category: Clippy is not doing the correct thing label Dec 31, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 31, 2024
Otto-AA added a commit to Otto-AA/rust-clippy that referenced this issue Dec 31, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 8, 2025
Fixes #13913 .

changelog: [`manual_is_ascii_check`]: fix type suggestions for
references

Previously it only derived `char` and `u8` types, now it should always
annotate the lambda parameter with the correct type (e.g. `&char`).

I'm quite new to Rust and this is my first contact with clippy, so I'm
open for suggetions :)
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants