-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
The f32 and f64 types have pub fn from_bits(u32) -> f32 and pub fn to_bits(f32) -> u32 methods, yet many users don't know about them, and use transmute instead.
We should add a lint unnecessary_float_transmute that:
-
detects a transmute between a floating-point type and the unsigned integer type of the same bit width, and recommends using either
from_bitsorto_bitsinstead. -
detects a transmute between a floating-point type and the signed integer type of the same bit-diwth, and recommends using
from_bits/to_bits+ anascast (from unsigned to signed or vice-versa) instead.
When one of the arguments to the transmute is a macro variable, this lint probably can't work correctly (e.g. the macro might be expanded with types that aren't floats), so the lint should bail.