Is transmute_int_to_float's justification reasonable? #3550
Labels
A-documentation
Area: Adding or improving documentation
good-first-issue
These issues are a good way to get started with Clippy
The lint
transmute_int_to_float
claims that transmuting directly from a float to an integer can lead to an invalid in-memory representation.This reason seems inaccurate at this point. What can result from transmutation of an integer to a float of the same size is a signalling NaN, which is currently not treated as an invalid representation, nor is it considered undefined behaviour. Moreover, the latest implementations of
from_bits
from the core library are equivalent totransmute<u32, f32>
andtransmute<u64, f64>
anyway (see for example f64::from_bits), so in practice the lint does not address the claimed issue.This does not invalidate the lint, since it provides a reasonable alternative to the use of an unsafe function that can do something really dangerous when used improperly (basically for the reasons described in #1675). What do you think of changing the "Why this is bad" explanation to the following?
The text was updated successfully, but these errors were encountered: