Open
Description
Summary
Clippy lint manual_flatten
doesn't follow its own suggestion to remove if let
statement leading to broken code.
Similar to #7514, but without references or slices.
Reproducer
I tried this code:
fn main() {
let results: Vec<Result<String, ()>> = vec![];
for result in results {
if let Ok(value) = result {
println!("{value}");
}
}
}
I expected to see this happen:
for result in results.into_iter().flatten() {
println!("{result}");
}
Instead, this happened:
for result in results.into_iter().flatten() {
if let Ok(value) = result { // broken because result is now of type String
println!("{value}");
}
}
Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7
Additional Labels
@rustbot label +I-suggestion-causes-error