Skip to content

manual_pattern_char_comparison should respect MSRV #12936

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
taiki-e opened this issue Jun 15, 2024 · 1 comment · Fixed by #12937
Closed

manual_pattern_char_comparison should respect MSRV #12936

taiki-e opened this issue Jun 15, 2024 · 1 comment · Fixed by #12937
Assignees
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

@taiki-e
Copy link
Member

taiki-e commented Jun 15, 2024

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

@taiki-e taiki-e 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 Jun 15, 2024
@AurelienFT
Copy link
Contributor

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # 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

Successfully merging a pull request may close this issue.

2 participants