Skip to content

Document UniqueArc and ArcBorrow interaction contract in more detail #146

Description

@michaelsproul

My LLM thinks it has found a bug. Demonstrated by this code which triggers UB under Miri:

use std::mem::MaybeUninit;

use triomphe::{ArcBorrow, UniqueArc};

fn main() {
    let mut unique = UniqueArc::<u8>::new_uninit();
    let borrow = unsafe { ArcBorrow::from_ptr(unique.as_mut_ptr()) };
    let arc = borrow.clone_arc();
    let shared = &*arc;

    *unique = MaybeUninit::new(0);
    std::hint::black_box(shared);
}

To me it seems a bit bullshit because it's clearly violating the intent of UniqueArc by using unsafe to create multiple pointers to its allocation. The LLM claims that technically there's nothing in the (textual) contract of ArcBorrow::from_ptr to prevent this.

Feel free to close if this is not useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions