Stream: t-lang

Topic: Sized vs thin

Simon Sapin (Feb 24 2020 at 20:52, on Zulip):

Does T: Sized necessarily imply that *const T is a thin pointer? This is the case in today’s Rust, but do we want to "promise" or document that it will always be?

Matthew Jasper (Feb 24 2020 at 21:20, on Zulip):

std::mem::transmute::<*const T, usize> is allowed, so it looks like it's guaranteed (at least on current targets).

nikomatsakis (Feb 24 2020 at 22:36, on Zulip):

I believe this is something we could not change, yes

nagisa (Feb 25 2020 at 13:36, on Zulip):

It’ll just operate on the data pointer I believe?

nagisa (Feb 25 2020 at 13:37, on Zulip):

@eddyb argued in the past that the vtable pointer is actually the part of T not *const.

nagisa (Feb 25 2020 at 13:37, on Zulip):

something along those lines.

nagisa (Feb 25 2020 at 13:38, on Zulip):

And so it is your responsibility to reconstruct the right vtable pointer if you want to convert usize to a fat pointer.

Simon Sapin (Feb 25 2020 at 17:47, on Zulip):

Yes you can cast a fat pointer with as and get the data part only, but transmute checks that size_of::<*const T>() == size_of::<usize>()

Last update: Jun 05 2020 at 23:20UTC