Skip to content

manual_is_ascii_check may produce invalid code #11776

Closed
@Szpadel

Description

@Szpadel

Summary

after fixes were automatically applied the compiler reported errors within these files:

  • src/serde/rgb.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the --broken-code flag

The following errors were reported:
error[E0282]: type annotations needed
--> src/serde/rgb.rs:17:14
|
17 | |chr| chr.is_ascii_hexdigit(),
| ^^^ --- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
17 | |chr: /* Type */| chr.is_ascii_hexdigit(),
| ++++++++++++

error: aborting due to previous error

For more information about this error, try rustc --explain E0282.
Original diagnostics will follow.

Reproducer

use nom::{
    bytes::complete::{tag, take_while_m_n},
    combinator::{all_consuming, map_res},
    sequence::tuple,
    IResult,
};

fn parse_2h(data: &str) -> IResult<&str, u8> {
    map_res(
        take_while_m_n(
            2,
            2,
            |chr| matches!(chr, 'a'..='f' | 'A'..='F' | '0'..='9' ),
        ),
        |s| u8::from_str_radix(s, 16),
    )(data)
}

Correct result would be:

            |chr: char| chr.is_ascii_hexdigit(),

Version

rustc 1.75.0-nightly (7adc89b69 2023-11-07)
binary: rustc
commit-hash: 7adc89b69b941afceadcf8609dd6b2999353e550
commit-date: 2023-11-07
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

Additional Labels

@rustbot +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions