Skip to content

Is assignment to an uninit but non-Drop place okay? #596

@ChayimFriedman2

Description

@ChayimFriedman2

I don't see an issue about this (although #307) is close, and I'm pretty sure this is undecided.

Can we use assignment (and not ptr::write()) to write to an uninitialized place of a type that does not have a drop glue? That is, this:

fn main() {
    let mut v = std::mem::MaybeUninit::<i32>::uninit();
    unsafe {
        *v.as_mut_ptr() = 123;
    }
}

Miri does not flag this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions