-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Take this code:
fn foo(v: Option<char>) -> u32 {
match v {
Some(w @ 'a' | w @ 'c' | w @ 'd') => w as u32,
Some(_) => 1,
None => 0,
}
}
The binding w
of the first arm's pattern is repeated three times. One can simplify the pattern as follows:
fn foo(v: Option<char>) -> u32 {
match v {
Some(w @ ('a' | 'c' | 'd')) => w as u32,
Some(_) => 1,
None => 0,
}
}
Lint Name
repetitive_capture
Category
style
Advantage
This saves repetition of the binding (less chars) and makes the code more maintainable as renames only affect one site instead of multiple
Drawbacks
It adds one layer of ()
s, but this should be bearable
Example
provided above
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy