RS.CLIPPY.MATCH_REF_PATS
A `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: match_ref_pats. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for matches where all arms match a reference,
suggesting to remove the reference and deref the matched expression
instead. It also checks for if let &foo = bar blocks.
Why is this bad?
It just makes the code less readable. That reference destructuring adds nothing to the code.
Example
match x {
&A(ref y) => foo(y),
&B => bar(),
_ => frob(&x),
}
Use instead:
match *x {
A(ref y) => foo(y),
B => bar(),
_ => frob(x),
}