RS.CLIPPY.OPTION_FILTER_MAP

Filtering `Option` for `Some` 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: option_filter_map. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for iterators of Options using .filter(Option::is_some).map(Option::unwrap) that may be replaced with a .flatten() call.

Why is this bad?

Option is like a collection of 0-1 things, so flatten automatically does this without suspicious-looking unwrap calls.

Example

let _ = std::iter::empty::<Option<i32>>().filter(Option::is_some).map(Option::unwrap);

Use instead:

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