RS.CLIPPY.MANUAL_UNWRAP_OR_DEFAULT
Check if a `match` or `if let` can be simplified with `unwrap_or_default`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_unwrap_or_default. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks if a match or if let expression can be simplified using
.unwrap_or_default().
Why is this bad?
It can be done in one call with .unwrap_or_default().
Example
let x: Option<String> = Some(String::new());
let y: String = match x {
Some(v) => v,
None => String::new(),
};
let x: Option<Vec<String>> = Some(Vec::new());
let y: Vec<String> = if let Some(v) = x {
v
} else {
Vec::new()
};
Use instead:
let x: Option<String> = Some(String::new());
let y: String = x.unwrap_or_default();
let x: Option<Vec<String>> = Some(Vec::new());
let y: Vec<String> = x.unwrap_or_default();