{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreicdjdpawoyr5ajyybhr6whi7e4xr6g5u7azukfkgt4nh6gmaquqwa",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgnl5gc4m642"
  },
  "path": "/t/idea-pre-rfc-null-free-pointer-and-zeroable-reference/23991?page=6#post_109",
  "publishedAt": "2026-03-08T08:23:25.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "rust#138351"
  ],
  "textContent": "Even setting all of that aside, `core` itself heavily depends on `&T`. This cannot be resolved by a third-party library, and even introducing alternatives within `core` would invite circular dependencies. Moreover, `&T` does not even live in `core`. It resides in the compiler as `TyKind::Ref`, and a single line in the layout computation ensures it can never reach 0x0:\n\n\n    // compiler/rustc_ty_utils/src/layout.rs:410-414\n    ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {\n        let mut data_ptr = scalar_unit(Pointer(AddressSpace::ZERO));\n        if !ty.is_raw_ptr() {\n            data_ptr.valid_range_mut().start = 1;\n        }\n\n\nThis single expression is where the non-null invariant is physically enforced. No library - whether in `core` or third-party - can reach below this.\n\nH4n_uL:\n\n> And looking at `replace_memory` in your `any_mem` sketch, that's the operation `ptr::replace` couldn't do soundly because it relies on `&mut *dst` internally (rust#138351).\n\nAs noted above, this has already led to a soundness issue.\n\nThe zeroable reference primitive proposed to address this may seem like an excessive solution at first glance, but consider `NonZero<T>`. Today, `NonZero<usize>` sits alongside `usize`, and the two coexist. `&T` currently occupies the position of `NonZero<usize>`, but the `usize` that should sit beside it is missing. This is not a new paradigm, nor a sledgehammer to crack a nut. It is simply restoring the missing counterpart of `NonZero<?> == &T`.",
  "title": "Idea / Pre-RFC: Null-free pointer and Zeroable reference"
}