# unnecessary-unwrap

Disallow unwrap after checked control flow proves the Result variant

Unwrapping a Result after control flow has already narrowed it repeats a variant check that is known to succeed.
Instead, you SHOULD read the narrowed variant payload directly.

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

## Reported

```ds title="main.ds"
function value(result: Result<int32, string>): int32 {
    if (result.kind === "Ok") {
        return result.unwrap();
    }
    return 0;
}
```

## Accepted

```ds title="main.ds"
function value(result: Result<int32, string>): int32 {
    if (result.kind === "Ok") {
        return result.value;
    }
    return 0;
}
```

## Prior art

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

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