RS.CLIPPY.NEEDLESS_MATCH
`match` or match-like `if let` that are unnecessary
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_match. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for unnecessary match or match-like if let returns for Option and Result
when function signatures are the same.
Why is this bad?
This match block does nothing and might not be what the coder intended.
Example
fn foo() -> Result<(), i32> {
match result {
Ok(val) => Ok(val),
Err(err) => Err(err),
}
}
fn bar() -> Option<i32> {
if let Some(val) = option {
Some(val)
} else {
None
}
}
Could be replaced as
fn foo() -> Result<(), i32> {
result
}
fn bar() -> Option<i32> {
option
}