3 ms·
It's a mix of both. https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#72-73 https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#72-7... #[rustc_lay
by conradludgate 1y ago
It's a mix of both. https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#72-73 https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#72-7...
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
This declares that NonNull cannot be outside of the range (1..). These magic attributes are only allowed to be used by the stdlib, and they're direct compiler instructions. Nonnull is special because the optimisation is guaranteed so the compiler does have special code to handle it, but other types can be optimised without compiler changes.