|
|
Log in / Subscribe / Register

Pointee not on the heap?

Pointee not on the heap?

Posted Apr 23, 2026 17:21 UTC (Thu) by tialaramex (subscriber, #21167)
In reply to: Pointee not on the heap? by pbonzini
Parent article: One Sized trait does not fit all

I think Rust is already comfortable with pointers where we know nothing whatsoever about the thing pointed to. Indeed unlike C++ Rust is comfortable with raw pointers which are not valid, so e.g. if you want to store the integer 5, or the text 'CLOWNS' in this 64-bit CPU register which has the type of a raw pointer to a Doodad, Rust is OK with that existing *so long* as you have ensured you will never try to dereference the pointer in the Rust. If you dereference a nonsense pointer that's UB, which is why dereferencing raw pointers is one of the handful of named unsafe "super powers" - it's on the programmer to make sure they only do this to valid pointers.

I think the idea with Pointee is that we know that there is something pointed to, but Rust doesn't know what and so will never know (not at compile time, not at execution start, not even at runtime) how big Pointee is. So I think Pointee in some sense isn't a new addition to the model, but the current status quo for "We don't know the size".


to post comments

Pointee not on the heap?

Posted Apr 23, 2026 19:07 UTC (Thu) by pbonzini (subscriber, #60935) [Link] (2 responses)

I *think* the difference is that you can have a &Pointee that points to invalid memory because it's guaranteed that Rust code will never actually access the memory. This can only happen by passing it back to another language via FFI, and whoever creates the &Pointee ensures that whoever receives it won't produce undefined behavior.

Pointee not on the heap?

Posted Apr 23, 2026 19:43 UTC (Thu) by daroc (editor, #160859) [Link] (1 responses)

I guess I didn't explain this well enough; Pointee is a subset of the current category !Sized. So current Rust code does handle things that would be Pointee.

The point of the RFC is that !Sized is really lumping two separate, useful categories together: SizeOfVal (where we don't know the size based on the type, but we can know the size of some particular value) and Pointee (where we can't know the size at all).

Pointee not on the heap?

Posted Apr 23, 2026 21:22 UTC (Thu) by pbonzini (subscriber, #60935) [Link]

Yes, what I meant is that not knowing the size at all has interesting effects on what constitutes a valid value of a reference.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds