{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiboh2mlkdd3bxdbl2jo3ngbqcq52j6ejlty2a7z3t2vge3kmpt2fm",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mlynj42lrxu2"
},
"path": "/t/reducing-raw-pointer-footguns-preventing-reference-aliasing-violations-at-compile-time/24301?page=2#post_21",
"publishedAt": "2026-05-16T09:05:02.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "That code avoids the point because it avoids mixing raw pointers and references, that is outside the scope of the discussion. The goal here is to explore mixing raw pointers and references in safer way, not to avoid mixing them. We want when we combine them we have stronger protections against accidental aliasing violations\n\nThe example above is a simulation of mixed raw pointer and reference usage. If we remove the raw pointer and replace everything with references, then we are no longer simulating the actual problem space. The entire point is that some operations fundamentally require raw pointers, such as FFI boundaries, low level memory manipulation, unsafe third party APIs, and similar systems level code\n\nSo the body of the example is not important by itself. The important part is: “assume this operation requires a raw pointer”. The example exists to model that situation\n\nAnother problem is that correct usage heavily depends on deep understanding of Rust’s aliasing and pointer invalidation rules. The code becomes extremely fragile because even changing the order of a few lines can silently introduce UB. That alone demonstrates there is room for improvement\n\nThe issue is that once raw pointers and references are involved, we must manually reason about:\n\n * when references become invalidated,\n * when raw pointers become invalidated,\n * whether aliasing rules are violated,\n * whether a later `&mut` creation silently invalidates previous pointers\n * whether a write through one path invalidates another path\n * etc maybe things that I do not know yet\n\n\n\nThat is extremely easy to get wrong that general user will get the footgun easily, compared to we have compile time error so general user will change the code\n\nTo design APIs that are practical and safer for real world users, then we should evaluate them from the perspective of average users, not only people with expert level understanding of Rust aliasing",
"title": "Reducing Raw Pointer Footguns: Preventing Reference Aliasing Violations at Compile Time"
}