RS.CLIPPY.ITER_FILTER_IS_SOME

Filtering an iterator over `Option`s for `Some` can be achieved with `flatten`

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

What it does

Checks for usage of .filter(Option::is_some) that may be replaced with a .flatten() call. This lint will require additional changes to the follow-up calls as it affects the type.

Why is this bad?

This pattern is often followed by manual unwrapping of the Option. The simplification results in more readable and succinct code without the need for manual unwrapping.

Example

vec![Some(1)].into_iter().filter(Option::is_some);

Use instead:

vec![Some(1)].into_iter().flatten();