I came across a usage of
*mut [T] in some documentation I was reading, and I find myself questioning why
*mut T doesn’t have
T: Sized. It’s not like there’s anything useful that can be done with
*mut [T]. You can:
- Cast to
*mut Tand do the usual C pointer shenanigans. This cast is UB, since the layout of a ptr-to-slice is unspecified.
- Go up through
(*mut _)::as_ref()to get a
&'unbounded [T]you can do something useful with (like
[_]::into_raw_parts()it into a
- Check for nullity.
I question whether you should be winding up in a situation where you have a
*mut Dst for
Dst: !Sized… if I wanted a raw pointer to a slice I’d want to keep track of the length separately. I have even bigger trouble imagining a use case for
*mut dyn Trait. If you need something like that there should probably be compiler support for breaking a trait object into a pointer + vtable beyond the shoddy mess that is
Moreover, because they’re meant for FFI, I feel like there’s an expectation that
*mut T always be an honest-to-God pointer. I’ve been writing Rust for a while now and I only recently learned there is no such guarantee!