You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_bits or to_bits instead.
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 + an as cast (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.
The text was updated successfully, but these errors were encountered:
gnzlbg
changed the title
transmute floats to ints and vice-versa
[lint request] unnecessary_float_transmute
Apr 18, 2019
The
f32
andf64
types havepub fn from_bits(u32) -> f32
andpub fn to_bits(f32) -> u32
methods, yet many users don't know about them, and usetransmute
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_bits
orto_bits
instead.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
+ anas
cast (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.
The text was updated successfully, but these errors were encountered: