Closed
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