Skip to content

Does writing through a raw pointer with an assignment assert validity for Copy types? #317

Closed
@nico-abram

Description

@nico-abram

Basically, is this UB?

use core::mem::MaybeUninit;

fn main() {
    let mut x = MaybeUninit::<&'static u8>::uninit();
    let xp = x.as_mut_ptr();
    unsafe {
        *xp = &0;
    }
}

MIRI accepts it, but it also accepts this other one which I think is UB

use core::mem::MaybeUninit;

fn main() {
    let mut x = MaybeUninit::<&'static u8>::uninit();
    unsafe {
        let xp = &mut*x.as_mut_ptr();
        *xp = &0;
    }
}

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