-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have