RS.CLIPPY.MATCH_RESULT_OK

Usage of `ok()` in `let Some(pat)` statements is unnecessary, match on `Ok(pat)` instead

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: match_result_ok. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for unnecessary ok() in while let.

Why is this bad?

Calling ok() in while let is unnecessary, instead match on Ok(pat)

Example

while let Some(value) = iter.next().ok() {
    vec.push(value)
}

if let Some(value) = iter.next().ok() {
    vec.push(value)
}

Use instead:

while let Ok(value) = iter.next() {
    vec.push(value)
}

if let Ok(value) = iter.next() {
       vec.push(value)
}

Past names

  • if_let_some_result