-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
match_like_matches_macro suggests turning match expressions to a matches! expression even if doing so results in the loss of comments and documentation on each match arm.
Lint Name
match_like_matches_macro
Reproducer
I tried this code:
fn y(c: char) -> bool {
match c {
// numbers are bad!
'1' | '2' | '3' => true,
// spaces are very important to be true.
' ' => true,
// as are dots
'.' => true,
_ => false,
}
}
fn main() {
dbg!(y('g'));
}I saw this happen:
Checking playground v0.0.1 (/playground)
warning: match expression looks like `matches!` macro
--> src/main.rs:2:5
|
2 | / match c {
3 | | // numbers are bad!
4 | | '1' | '2' | '3' => true,
5 | | // spaces are very important to be true.
... |
9 | | _ => false,
10 | | }
| |_____^ help: try this: `matches!(c, '1' | '2' | '3' | ' ' | '.')`
|
= note: `#[warn(clippy::match_like_matches_macro)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
warning: `playground` (bin "playground") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.43s
I expected to see this happen: comments are preserved or the lint is not triggered.
Version
rust 1.62.0 (playground)
Additional Labels
No response
choznerol
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have