Skip to content

Is it sound to split an UnsafeCell into multiple UnsafeCells? #458

Closed
@joshlf

Description

@joshlf

Miri doesn't complain about the following code, but is this guaranteed to be sound?

fn main() {
    let x = UnsafeCell::new([0u8; 2]);
    let x = &x;
    let x_ptr: *const UnsafeCell<[u8; 2]> = x;
    let y_ptr = x_ptr as *const [UnsafeCell<u8>; 2];
    let _y = unsafe { &*y_ptr };
}

I read #451 (comment) as implying this is intended to be sound, but I wanted to double-check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions