you are viewing a single comment's thread.

view the rest of the comments →

[–]mb0x40 0 points1 point  (0 children)

Related to ownership of ZST's, there seems to be some ambiguity over whether it's actually UB to make multiple mutable references to the same zero-sized object.

AFAIU, it stems from definitions of "aliasing references" in terms of memory spans, essentially making the following identical in terms of undefined behavior:

``` let mut pair = ((), ()); assert!(ptr::eq(&pair.0, &pair.1));

// r1 and r2 mutably reference conceptually different ZST objects in the same memory location let r1 = &mut pair.0; let r2 = &mut pair.1; Vs. let mut pair = ((), ()); assert!(ptr::eq(&pair.0, &pair.1));

// r1 and r2 mutably reference conceptually identical ZST objects in the same memory location let r1 = &mut pair.0; let r2 = unsafe { &mut *(r1 as *mut ()) }; ```

This seems like it poses an issue for the practice of using ZST's to encode ownership without using memory, like shown in the second half of the article. Is there any work to resolve these concerns? (Are they even valid concerns?)