Is accessing Reference.field Undefined Behavior if the Reference's Tag has been popped?

โš“ Rust    ๐Ÿ“… 2026-02-25    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

I am investigating a specific case of Undefined Behavior (UB) under the Stacked Borrows memory model. I would like to confirm the physical mechanism of memory access when a referenceโ€™s tag is no longer present in the borrow stack.

The Scenario

Suppose we have a structured type and a reference ref_a: &T (or &mut T) pointing to it. Due to a subsequent write operation via a raw pointer or a different unique reference, the Tag associated with ref_a is physically popped from the borrow stack of the underlying memory.

If the code subsequently attempts to access a nested field:

Rustlet x = ref_a.field_a.field_b;

Is it an UB? Miri does not report such an error:

6 posts - 3 participants

Read full topic

๐Ÿท๏ธ Rust_feed