-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does writing through a raw pointer with an assignment assert validity for Copy types? #317
Comments
I am confused by the examples, could you explain their point? Potentially related: #84 |
Why would either of them be UB? The only thing I can think is that writing to |
Before asking something in zulip (https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Question.20about.20addr_of!.20and.20nested.20derefs) I asked in the community discord server's #dark-arts, where someone mentioned that a snippet like the following that tries to partially initialize a MaybeUninit struct struct Y { data: u8, _r: &'static u8 }
let mut y: MaybeUninit<Y> = MaybeUninit::uninit();
let y_ptr = &mut y as *mut _ as *mut Y;
(*y_ptr).data = 1u8; Was wrong because The motivation is knowing if using raw pointer dereferences to uninitialized data on the left side of an assignment is incorrect, specifically for Copy types (With or without niches). So dereferencing a The |
Yes, this was my understanding. It's only UB if it is Drop. But someone told me it still asserted validity for Copy types which is why I'm asking. Isn't the second example UB because it is making a
|
Oh you are asking if the old data that is being overwritten has to be valid? That wasn't clear at all from your question. :) No it does not. |
Yes, I meant the old data. Thanks for the answer |
Basically, is this UB?
MIRI accepts it, but it also accepts this other one which I think is UB
The text was updated successfully, but these errors were encountered: