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
Currently, some uses of the as operator are not entirely safe. In particular, it is undefined behavior if:
...
Or a floating point value does not fit in another floating point type (#15536)
However, issue 15536 is closed and fixed, as far as I understand, and this is not undefined behavior anymore (in fact, it was never really undefined behavior; the LLVM docs described it as such, but those docs have been clarified).
It looks like the warning in the documentation of AsPrimitive is not accurate anymore.
The text was updated successfully, but these errors were encountered:
The float as float issue was deemed safe -- we can remove that.
But up through Rust 1.44, float as int is still UB if it overflows. In Rust 1.45, that operation will instead be defined to saturate, so only then it will be safe. We should probably still clarify this situation in the AsPrimitive docs.
Semi-related, #162 started using to_int_unchecked() in cases where we've already checked the boundary conditions, to avoid any possible performance hit of the upcoming saturation.
The documentation of
num_traits::cast::AsPrimitive
warns about undefined behavior:However, issue 15536 is closed and fixed, as far as I understand, and this is not undefined behavior anymore (in fact, it was never really undefined behavior; the LLVM docs described it as such, but those docs have been clarified).
It looks like the warning in the documentation of
AsPrimitive
is not accurate anymore.The text was updated successfully, but these errors were encountered: