Gilnaa / memoffset

offsetof for Rust
MIT License
224 stars 29 forks source link

span_of is unsound due to size_of_val #52

Closed RalfJung closed 3 years ago

RalfJung commented 3 years ago

span_of creates a reference to an uninitialized field for size_of_val.

We should switch to a different implementation that works with raw pointers. It doesn't even have to support unsized types (we just need the type inference), so we could use

fn size_of_pointee<T>(_ptr: *const T) -> T {
  mem::size_of::<T>()
}