Assignment written as =- or =! instead of -= or !=

ID

rust.correctness.assignment_operators_confused_comparison_compound

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Construct

Language

Rust

Description

The spacing here reads as a single =- or =! operator, but Rust parses it as an assignment of a negated value. If a compound assignment (-=) or a comparison (!=) was meant, write that operator; otherwise put a space after the = so the intent is unambiguous.

Rationale

The spacing here reads as a single =- or =! operator, but Rust parses it as an assignment of a negated value. If a compound assignment (-=) or a comparison (!=) was meant, write that operator; otherwise put a space after the = so the intent is unambiguous.

The following code illustrates the pattern detected by this rule:

pub fn accumulate(mut total: i32, delta: i32) -> i32 {
    // FLAGGED: Assignment written as `=-` or `=!` instead of `-=` or `!=`
    total =- delta;
    total
}

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