Comparison against a type bound is always true or always false

ID

rust.correctness.absurd_extreme_comparisons

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Construct

Language

Rust

Description

This comparison can never change: the operand’s type cannot hold a value outside the range being tested, so the condition is a constant. Drop the check, or compare against the real limit the code cares about.

Rationale

This comparison can never change: the operand’s type cannot hold a value outside the range being tested, so the condition is a constant. Drop the check, or compare against the real limit the code cares about.

The following code illustrates the pattern detected by this rule:

pub fn unsigned_bounds(a: u32, b: u8, c: usize) -> u32 {
    // FLAGGED: Comparison against a type bound is always true or always false
    if a >= 0 {
        return 1;
    }
    // FLAGGED: Comparison against a type bound is always true or always false
    if b < 0 {
        return 2;
    }
    // FLAGGED: Comparison against a type bound is always true or always false
    if 0 > c {
        return 3;
    }
    if a > 0 {
        return 4;
    }
    0
}

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