Open
Description
Inspired by #124861, specifically glium/glium@ebdc18e
There's no reason to use an unsafe transmute to get a pointer from a reference, and as that code example shows it can easily hide bugs. We should (at least) warn about it.
- For
&T
to*const T
, recommend https://doc.rust-lang.org/std/ptr/fn.from_ref.html (machine-applicable, because it's always right) - For
&mut T
to*mut T
, recommend https://doc.rust-lang.org/std/ptr/fn.from_mut.html (machine-applicable, because it's always right) - For
&T
to*mut T
, recommendfrom_ref
+cast_mut
, but not auto-applicable because we should comment that it's probably wrong, and they probably wantfrom_mut
instead, but that will require larger reworking of the code. - For
&mut T
to*const T
, recommend https://doc.rust-lang.org/std/ptr/fn.from_mut.html with a note that in a generic context it might also need.cast_const()
.