RS.CLIPPY.OPTION_OPTION

Usage of `Option<Option<T>>`

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_option. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of Option<Option<_>> in function signatures and type definitions

Why is this bad?

Option<_> represents an optional value. Option<Option<_>> represents an optional value which itself wraps an optional. This is logically the same thing as an optional value but has an unneeded extra level of wrapping.

If you have a case where Some(Some(_)), Some(None) and None are distinct cases, consider a custom enum instead, with clear names for each case.

Example

fn get_data() -> Option<Option<u32>> {
    None
}

Better:

pub enum Contents {
    Data(Vec<u8>), // Was Some(Some(Vec<u8>))
    NotYetFetched, // Was Some(None)
    None,          // Was None
}

fn get_data() -> Contents {
    Contents::None
}

Configuration

  • avoid-breaking-exported-api: Suppress lints whenever the suggested change would cause breakage for other crates.

    (default: true)