Search adaptor whose result is only tested for presence

ID

rust.maintainability.search_is_some

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Inefficient Api Usage

Language

Rust

Description

Reports find, find_map, position or rposition whose returned Option is immediately discarded by is_some() or is_none(), so the search result itself is never used.

Rationale

Producing a value and then asking only whether it exists forces the reader to check that the item really is unused before concluding the line is a membership test. any() says that in one call, and for find_map it also avoids building the mapped value that is thrown away.

The following code illustrates the pattern detected by this rule:

pub struct User {
    pub name: String,
    pub admin: bool,
}

pub fn has_admin(users: &[User]) -> bool {
    // FLAGGED: Search adaptor whose result is only tested for presence
    users.iter().find(|u| u.admin).is_some()
}

Remediation

Replace .find(p).is_some() with .any(p) and .find(p).is_none() with !…​any(p). position/rposition take the same predicate, so they convert the same way; for find_map(f).is_some() use .any(|x| f(x).is_some()).

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved