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

No documentation on why packed types + Drop aren't UB #54148

Closed
strega-nil opened this issue Sep 12, 2018 · 12 comments
Closed

No documentation on why packed types + Drop aren't UB #54148

strega-nil opened this issue Sep 12, 2018 · 12 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@strega-nil
Copy link
Contributor

strega-nil commented Sep 12, 2018

https://play.rust-lang.org/?gist=73b84464abe00fb3564dbe30f10a4da7&version=stable&mode=debug&edition=2015

<Dropper as Drop>::drop is passed an unaligned reference to Dropper, which is UB.

cc @rust-lang/lang

@sfackler
Copy link
Member

#27060

@matthewjasper
Copy link
Contributor

@strega-nil
Copy link
Contributor Author

@sfackler Putting Drop types in a #[repr(packed)] structure should also be deprecated, then.

@strega-nil
Copy link
Contributor Author

Ah, nevermind; apparently, we generate a shim that copies the value before calling drop on it. We should document this.

@eddyb
Copy link
Member

eddyb commented Sep 12, 2018

cc @arielb1

@alercah
Copy link
Contributor

alercah commented Sep 12, 2018

Is it possible to break it if Dropper is immovable?

@cramertj
Copy link
Member

@alercah @RalfJung just left a comment about that on the Pin tracking issue.

@RalfJung
Copy link
Member

RalfJung commented Sep 13, 2018 via email

@alercah
Copy link
Contributor

alercah commented Sep 13, 2018

The reference seems like the right place for it.

@strega-nil
Copy link
Contributor Author

Or the Rustonomicon?

@strega-nil strega-nil changed the title Packed types allow UB without unsafe No documentation on why packed types + Drop aren't UB Sep 13, 2018
@strega-nil strega-nil reopened this Sep 13, 2018
@alercah
Copy link
Contributor

alercah commented Sep 13, 2018

I think the long-term vision should be the reference holding normative text, and the 'Nomicon being more of a practical guide. So probably the correct answer is both.

@memoryruins memoryruins added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Sep 15, 2018
@steveklabnik
Copy link
Member

re-filing against the reference rust-lang/reference#488

if anyone wants to put this in the nomicon, they can, but it's optional, IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

No branches or pull requests

9 participants