# no-collapsible-match

Merge nested matches whose nested pattern fits the enclosing arm

A nested match on a value bound by its enclosing arm repeats the same selection in two places.
Instead, you SHOULD place the nested pattern at the binding site when both fallback arms have the same result.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function describe(result: Result<int32, string>): string {
    return match (result) {
        Ok { value } => match (value) {
            0 => "zero"
            _ => "other"
        }
        _ => "other"
    };
}
```

## Accepted

```ds title="main.ds"
function describe(result: Result<int32, string>): string {
    return match (result) {
        Ok { value: 0 } => "zero"
        _ => "other"
    };
}
```

## Prior art

- [Clippy · collapsible_match](https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match)

[language/linter/src/rules/style/no_collapsible_match.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/no_collapsible_match.rs#L8)
