Stream: t-compiler

Topic: Box of external type and Drop

NeoRaider (May 01 2020 at 17:48, on Zulip):

Oookay, so I have the following setup:

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: - 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.


RalfJ (May 02 2020 at 13:33, on Zulip):

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.

Jake Goulding (May 02 2020 at 13:46, on Zulip):

Implement deref and/or derefmut and drop and you are good to go

Jake Goulding (May 02 2020 at 13:58, on Zulip):

And might as well make your newtype repr(transparent)

NeoRaider (May 02 2020 at 14:54, on Zulip):

Thanks, that's what I went for.

Last update: May 29 2020 at 17:05UTC