notriddle / rust-float-ord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible unsoundness in `sort` function

mexus opened this issue · comments

commented

First of all, thanks for the cool and useful crate :)

There's a transmute of [T] to [FloatOrd<T>] on https://github.com/notriddle/rust-float-ord/blob/master/src/lib.rs#L71, but this only make sense if FloatOrd is a "transparent" wrapper: https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent

While currently rustc doesn't add any padding to the generated struct, but theoretically in a future release the compiler might start to twist the layout without further notice.

To stay on the safe, I propose to add a #[transparent] attribute to the FloatOrd definition.

Thanks!