RS.CLIPPY.UNIT_CMP

Comparing unit values

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

What it does

Checks for comparisons to unit. This includes all binary comparisons (like == and <) and asserts.

Why is this bad?

Unit is always equal to itself, and thus is just a clumsily written constant. Mostly this happens when someone accidentally adds semicolons at the end of the operands.

Example

if {
    foo();
} == {
    bar();
} {
    baz();
}

is equal to

{
    foo();
    bar();
    baz();
}

For asserts:

assert_eq!({ foo(); }, { bar(); });

will always succeed