RS.CLIPPY.NEG_CMP_OP_ON_PARTIAL_ORD

The use of negated comparison operators on partially ordered types may produce confusing code.

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

What it does

Checks for the usage of negated comparison operators on types which only implement PartialOrd (e.g., f64).

Why is this bad?

These operators make it easy to forget that the underlying types actually allow not only three potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is especially easy to miss if the operator based comparison result is negated.

Example

let a = 1.0;
let b = f64::NAN;

let not_less_or_equal = !(a <= b);

Use instead:

use std::cmp::Ordering;

let _not_less_or_equal = match a.partial_cmp(&b) {
    None | Some(Ordering::Greater) => true,
    _ => false,
};