RS.CLIPPY.MANUAL_FLATTEN
For loops over `Option`s or `Result`s with a single expression can be simplified
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_flatten. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for unnecessary if let usage in a for loop
where only the Some or Ok variant of the iterator element is used.
Why is this bad?
It is verbose and can be simplified
by first calling the flatten method on the Iterator.
Example
let x = vec![Some(1), Some(2), Some(3)];
for n in x {
if let Some(n) = n {
println!("{}", n);
}
}
Use instead:
let x = vec![Some(1), Some(2), Some(3)];
for n in x.into_iter().flatten() {
println!("{}", n);
}
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)