---
title: Redundant pattern match on Result or Option
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Redundant pattern match on Result or Option
---

# Redundant pattern match on Result or Option

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `rust-code-quality/redundant-pattern-matching`

**Language:** Rust

**Severity:** Warning

**Category:** Code Style

## Description{% #description %}

Using `if let` or `while let` to match `Ok`, `Err`, `Some`, or `None` just to check presence is unnecessarily verbose. Use the corresponding method instead: `is_ok()`, `is_err()`, `is_some()`, or `is_none()`. This is shorter and more idiomatic Rust.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```rust
if let Ok(_) = Ok::<i32, i32>(42) {}
if let Err(_) = Err::<i32, i32>(42) {}
if let None = None::<()> {}
while let Some(_) = some_option {}

if let Ok(_) = some_result {
    println!("ok");
} else {
    println!("err");
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```rust
if Ok::<i32, i32>(42).is_ok() {}
if Err::<i32, i32>(42).is_err() {}
if None::<()>.is_none() {}
while some_option.is_some() {}

if let Ok(val) = some_result {
    println!("{}", val);
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 