Skip to content

collapsible_match ​

Default: Enabled

Source Code

What it does ​

Checks for nested match statements that can be collapsed into a single match statement. Note that this lint is not intended to find all cases where nested match patterns can be merged, but only cases where merging would most likely make the code more readable.

Example ​

cairo
fn func(opt: Option<Result<u32, felt252>>) {
    let n = match opt {
        Some(n) => match n {
            Ok(n) => n,
            _ => return,
        }
        None => return,
    };
}

Can be collapsed to

cairo
fn func(opt: Option<Result<u32, felt252>>) {
    let n = match opt {
        Some(Ok(n)) => n,
        _ => return,
    };
}