RS.CLIPPY.CAST_SIGN_LOSS

Casts from signed types to unsigned types, e.g., `x as u32` where `x: i32`

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

What it does

Checks for casts from a signed to an unsigned numeric type. In this case, negative values wrap around to large positive values, which can be quite surprising in practice. However, since the cast works as defined, this lint is Allow by default.

Why is this bad?

Possibly surprising results. You can activate this lint as a one-time check to see where numeric wrapping can arise.

Example

let y: i8 = -1;
y as u64; // will return 18446744073709551615