Value allocated only to be compared

ID

rust.performance.cmp_owned

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Inefficient Api Usage

Language

Rust

Description

This comparison allocates an owned copy of the operand and then throws it away. PartialEq is implemented between borrowed and owned string types, so compare the borrowed values directly (candidate == expected, or owned.as_str() == borrowed) and drop the conversion.

Rationale

This comparison allocates an owned copy of the operand and then throws it away. PartialEq is implemented between borrowed and owned string types, so compare the borrowed values directly (candidate == expected, or owned.as_str() == borrowed) and drop the conversion.

The following code illustrates the pattern detected by this rule:

fn matches_name(candidate: &str, expected: &str) -> bool {
    // FLAGGED: Value allocated only to be compared
    candidate.to_string() == expected
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved