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

Validity of ManuallyDrop, or: ManuallyDrop<Box<_>> is strange #245

Open
RalfJung opened this issue Aug 12, 2020 · 0 comments
Open

Validity of ManuallyDrop, or: ManuallyDrop<Box<_>> is strange #245

RalfJung opened this issue Aug 12, 2020 · 0 comments
Labels
A-validity Topic: Related to validity invariants C-open-question Category: An open question that we should revisit

Comments

@RalfJung
Copy link
Member

The ManuallyDrop docs say

ManuallyDrop is subject to the same layout optimizations as T. As a consequence, it has no effect on the assumptions that the compiler makes about its contents.

In particular, this means that a ManuallyDrop<Box<T>> must not dangle. But that means that after calling drop on a ManuallDrop<Box<T>>, that value violates the validity invariant and must not be used or passed around any more! I don't think that is the behavior we want.

We want ManuallyDrop to preserve niches, so we cannot really relax what it says about validity. But what we could relax is validity of Box -- we could say that validity is purely about the pointer value itself (it must be non-NULL and properly aligned). We could specify that the "dereferencability" only comes in through the aliasing model, and we could make that model stop looking into ManuallyDrop.

@RalfJung RalfJung added C-open-question Category: An open question that we should revisit A-validity Topic: Related to validity invariants labels Aug 12, 2020
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 26, 2024
…homcc,traviscross

Document subtleties of `ManuallyDrop`

After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR.

See also rust-lang/unsafe-code-guidelines#245
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 27, 2024
Rollup merge of rust-lang#130279 - theemathas:manually-drop-docs, r=thomcc,traviscross

Document subtleties of `ManuallyDrop`

After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR.

See also rust-lang/unsafe-code-guidelines#245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-validity Topic: Related to validity invariants C-open-question Category: An open question that we should revisit
Projects
None yet
Development

No branches or pull requests

1 participant