Skip to content
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

ManuallyDrop layout guarantees? #302

Closed
joshlf opened this issue Aug 26, 2021 · 9 comments
Closed

ManuallyDrop layout guarantees? #302

joshlf opened this issue Aug 26, 2021 · 9 comments

Comments

@joshlf
Copy link

joshlf commented Aug 26, 2021

The docs for ManuallyDrop state:

ManuallyDrop<T> is subject to the same layout optimizations as T.

This hints, but does not explicitly guarantee, that ManuallyDrop<T> has the same layout as T. Do we want to guarantee that?

@thomcc
Copy link
Member

thomcc commented Aug 26, 2021

That line, and the fact that its #[repr(transparent)] (and documented as such), probably does guarantee this. But yeah, its probably worth being clear about.

@joshlf
Copy link
Author

joshlf commented Aug 26, 2021

Put up a documentation PR. Will wait to move forward with that until the discussion here is resolved.

@memoryruins
Copy link

@thomcc

and the fact that its #[repr(transparent)] (and documented as such)

rustdoc documents the repr whether or not the library guarantees what its private field contains, which sometimes leads to users assuming too much about the inner private field (e.g. rust-lang/rust#72841 (review)). I agree it would be good to clarify this for ManuallyDrop in the docs (and wonder if any other types in std could benefit from clarification).

@thomcc
Copy link
Member

thomcc commented Aug 27, 2021

which sometimes leads to users assuming too much about the inner private field

In this case, it's very clear that the inner field is a T.

But either way, I think this has been de-facto guaranteed for a while now. It changing would break a lot of existing code, and seems like it was always the intent, so we should guarantee it.

@joshtriplett
Copy link
Member

This seems right to me as well; repr(transparent) needs to guarantee this, and the fact that ManuallyDrop is repr(transparent) seems like a very public and required part of ManuallyDrop's ABI that we cannot and should not change.

@joshlf
Copy link
Author

joshlf commented Sep 4, 2021

Is there a path forward to this becoming an official position of the UCG WG? Not sure what the rules of parliamentary procedure are for the WG 😛

@Lokathor
Copy link
Contributor

Lokathor commented Sep 4, 2021

Nothing anywhere in this repo is official.

The intended path is that when something is ready to be official then it should just go though the RFC process.

@RalfJung
Copy link
Member

RalfJung commented Sep 4, 2021

We really need some procedure by which to declare a libstd repr(transparent) as an explicit stable guarantee...

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 28, 2022
Clarify that ManuallyDrop<T> has same layout as T

This PR implements the documentation change under discussion in rust-lang/unsafe-code-guidelines#302. It should not be approved or merged until the discussion there is resolved.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 28, 2022
Clarify that ManuallyDrop<T> has same layout as T

This PR implements the documentation change under discussion in rust-lang/unsafe-code-guidelines#302. It should not be approved or merged until the discussion there is resolved.
@ChayimFriedman2
Copy link

I guess this should be closed? rust-lang/rust#88375 is merged by now.

@joshlf joshlf closed this as completed Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants