-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
Currently, the documentation of clippy::cast_sign_loss
says the following:
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.
This accurately describes the problem the lint is supposed to detect in the integer domain.
However, the lint also reports floating point to integer casts, which behave differently from what is described. See #14356 and numeric cast semantics. Right now, the documentation is just plain wrong for floating point types. While the sign is lost in a float -> uint cast, the value does not wrap around. All negative float values map to 0 instead.
This makes it seems like reporting float -> uint casts is not intended. Please either adjust the documentation or do not report float -> uint casts.
I believe that not reporting float -> uint casts would be the best option. float -> uint and int -> uint casts can both cause sign loss, but for entirely different reasons. int -> uint casts also have a simple fix with cast_signed
and cast_unsigned
(#14974) to make the intention clear. float -> uint casts do not. As such, I believe that moving float -> uint casts to their own lint (#14356) or adding an option to suppress reports of those casts would be best.
Version
Additional Labels
@rustbot label +A-documentation