-
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
Documentation for ManuallyDrop
seems to contradict itself
#233
Comments
Notice the types are different. It makes all the difference.
A reference in rust has many rules, one of which is that it can never be null. |
@Lokathor Having thought about it a bit more, I think the problem with the docs is with this line:
This is at best misleading: after running the destructor, the wrapped value is not the same thing as uninitialised data: it is a sequence of bytes which are guaranteed to be valid under the validity rules for |
Are they even that? |
Oh, well yes. It's logically uninitialized, not physically uninitialized, i suppose the docs should say. if that distinction makes sense. |
(oops, that was to Diggsey, comex sniped me by a few seconds) |
If so, then the rules for what can be in a
edit: |
I agree that this wording is bad:
The value is not uninitialized. It is, in fact, the same value as before. In particular it satisfies anything that enum optimizations rely on. If validity invariants make assumptions about memory contents (which I am increasingly inclined to think they should not), then we need something weaker, which people have called "bit-level validity", and that is the part that layout optimizations rely on. But I think we should just avoid that extra layer. Instead, the fact that references and
Agreed (modulo packed structs). Do you want to submit a PR? |
What is the caveat regarding packed structs? |
Packed structs have to move their fields even for |
@RalfJung ah, but we can still say that |
@Diggsey true. I feel we should call out the packed-struct exception somewhere though. Maybe in the |
… r=RalfJung Improve the documentation for ManuallyDrop to resolve conflicting usage of terminology cc @RalfJung Follow-up from rust-lang/unsafe-code-guidelines#233
This has been closed by rust-lang/rust#71625. Thanks @Diggsey! |
So which is it? Is
ManuallyDrop
allowed to contain uninitialised data, or isManuallyDrop::drop
always insta-UB to call? What counts as "using" aManuallyDrop
type after dropping it?edit:
On a related note, the documentation for
ManuallyDrop::drop
should probably guarantee that the value is dropped in-place, without moving (and is thus OK to use with pinned data).The text was updated successfully, but these errors were encountered: