Skip to content

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

Open
@RalfJung

Description

@RalfJung

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-validityTopic: Related to validity invariantsC-open-questionCategory: An open question that we should revisit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions