RS.CLIPPY.MATCH_AS_REF
A `match` on an Option value instead of using `as_ref()` or `as_mut`
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_as_ref. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for match which is used to add a reference to an
Option value.
Why is this bad?
Using as_ref() or as_mut() instead is shorter.
Example
let x: Option<()> = None;
let r: Option<&()> = match x {
None => None,
Some(ref v) => Some(v),
};
Use instead:
let x: Option<()> = None;
let r: Option<&()> = x.as_ref();