Skip to content

manual_pattern_char_comparison should respect MSRV #12936

Closed

Description

@taiki-e

Summary

Pattern<'_> for [char; N] needs Rust 1.58, but this lint also suggests using it for code with MSRV less than 1.58.

Mentioning @AurelienFT, who implemented this lint in #12849.

Lint Name

manual_pattern_char_comparison

Reproducer

I tried this code:

#![warn(clippy::manual_pattern_char_comparison)]

#[clippy::msrv = "1.57"]
fn _f() {
     let _ = "abc".replace(|c: char| c == 'b' || c == 'c', "a");
}

I saw this happen:

warning: this manual char comparison can be written more succinctly
 --> src/lib.rs:5:28
  |
5 |      let _ = "abc".replace(|c: char| c == 'b' || c == 'c', "a");
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['b', 'c']`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::manual_pattern_char_comparison)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

However, the suggested code cases compile error on MSRV (Rust 1.57): https://godbolt.org/z/fdzGY6vbc

error[E0277]: expected a `FnMut<(char,)>` closure, found `[char; 2]`
 --> <source>:6:28
  |
6 |      let _ = "abc".replace(['b', 'c'], "a");
  |                    ------- ^^^^^^^^^^ expected an `FnMut<(char,)>` closure, found `[char; 2]`
  |                    |
  |                    required by a bound introduced by this call
  |
  = help: the trait `FnMut<(char,)>` is not implemented for `[char; 2]`
  = note: required because of the requirements on the impl of `Pattern<'_>` for `[char; 2]`

I expected to see this happen: no warning

playground

Version

rustc 1.81.0-nightly (f8e566053 2024-06-14)
binary: rustc
commit-hash: f8e566053207b4ecbcbc7a7d6ded82c43061e3da
commit-date: 2024-06-14
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on Jun 15, 2024
  2. AurelienFT commented on Jun 15, 2024

    @AurelienFT
    Contributor

    @rustbot claim

  3. added a commit that references this issue on Jun 15, 2024
    82345c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions