RS.CLIPPY.INVALID_UPCAST_COMPARISONS

A comparison involving an upcast which is always true or false

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

What it does

Checks for comparisons where the relation is always either true or false, but where one side has been upcast so that the comparison is necessary. Only integer types are checked.

Why is this bad?

An expression like let x : u8 = ...; (x as u32) > 300 will mistakenly imply that it is possible for x to be outside the range of u8.

Example

let x: u8 = 1;
(x as u32) > 300;