Closed quarthex closed 1 year ago
The lint applies on 8-bits platforms, though.
Rust will never support platforms where u/isize
is smaller than 16 bits and this lint is always incorrect. In fact isize::from(u8)
exists, which means it definitely is a lossless conversion.
@asquared31415 If it want to be considered as a language targeted for embedded development, Rust should be able to produce code for such platforms. In my company, we are trying to deal with shortages of microcontrollers such as STM32 (mainly reserved by the car industry) and we will use TinyAVR micrcontrollers instead. So, saying that Rust will never support 8-bit platforms is a little dramatic from my point of view.
Unfortunately Rust has already made guarantees that are incompatible with that. It's well documented that usize
is at least 16 bits large in The Reference and changing that would also require breaking changes to the standard library, namely the removal of the isize::from(u8)
impl.
Summary
The lint
cast_possible_wrap
is triggered by a conversion fromu8
toisize
.The displayed message is:
On 16/32/64-bits platforms, the message is wrong. An 8-bit unsigned value fits in a 16/32/64-bits signed register.
Reproducer
Version
Additional Labels
@rustbot label +I-false-positive +L-pedantic