External Publication
Visit Post

Idea / Pre-RFC: Null-free pointer and Zeroable reference

Rust Internals [Unofficial] March 7, 2026
Source

H4n_uL:

Relying on field projection and reborrow means this solution depends on two RFCs that are both still open experiments. If either changes direction or stalls, the entire library path disappears. This is the weakest link.

The library path doesn't disappear without these features, it just remains somewhat unergonomic.

H4n_uL:

Also, ergonomics matters more than it might seem - field_definition!(S, field_name) + *field!(&mut T, field_name) vs pointer.field won't be a minor difference when you're working with dozens of struct fields.

It's a very exotic usecase, so I don't think that's a big deal if it's a bit verbose until rust adds native field projection support. Cell and MaybeUninit don't have field projection support either, and those are much more common.

H4n_uL:

impl GetField<Container, Field> for &'t Container {

This is an instant UB when ptr is 0x0.

That function doesn't receive a pointer, it receives a reference, which can't be null. That playground only demonstrates how field projections can work in stable rust, not how to handle usable null pointers.

For usable null pointers you'd need something like this playground

Discussion in the ATmosphere

Loading comments...