Oookay, so I have the following setup:
Box<T>-> With my custom allocator, allocating a struct from C and dropping the Box, or allocating as Box and freeing from C should be fine
externtypes for opaque C structs
Now I'm wondering if it would be possible to extend GlobalAlloc in a way that would allow allocators that don't need to know the layout for dealloc? I assume doing this in a backwards-compatible way would be very difficult and likely not worth the added complexity...
If this is not feasible, should we at least add a lint against creating a Box of an
extern type? Directly related: https://github.com/rust-lang/rust/issues/49708 - if we had a trait that would disallow size_of_val and align_of_val for
extern types, the same trait bound could be added to Box<T>, as a Box of something that can't be deallocated doesn't make sense IMO.
My first thought would be to not use
Box, but roll your own "owned pointer" type. I think you are leaving the space
Box is designed for.
Implement deref and/or derefmut and drop and you are good to go
And might as well make your newtype repr(transparent)
Thanks, that's what I went for.