RS.CLIPPY.RESULT_FILTER_MAP

Filtering `Result` for `Ok` then force-unwrapping, which can be one type-safe operation

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: result_filter_map. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for iterators of Results using .filter(Result::is_ok).map(Result::unwrap) that may be replaced with a .flatten() call.

Why is this bad?

Result implements IntoIterator<Item = T>. This means that Result can be flattened automatically without suspicious-looking unwrap calls.

Example

let _ = std::iter::empty::<Result<i32, ()>>().filter(Result::is_ok).map(Result::unwrap);

Use instead:

let _ = std::iter::empty::<Result<i32, ()>>().flatten();