Skip to content

ManuallyDrop should be a dyn-compatible receiver type #64351

Open
@withoutboats

Description

@withoutboats

We should extend the set of library-defined self types on stable to include types involving ManuallyDrop. ManuallyDrop is a transparent wrapper around another type which is completely unconstrained; there should be no technical limitations on making it an dyn-compatible1 receiver type.

To be explicit, I am proposing to make the following types valid self types on stable, and all but the first would be dyn-compatible:

  • ManuallyDrop<Self>
  • &ManuallyDrop<Self>
  • &mut ManuallyDrop<Self>
  • Box<ManuallyDrop<Self>>
  • Rc<ManuallyDrop<Self>>
  • Arc<ManuallyDrop<Self>>
  • Pin<&ManuallyDrop<Self>>
  • Pin<&mut ManuallyDrop<Self>>
  • Pin<Box<ManuallyDrop<Self>>>
  • Pin<Rc<ManuallyDrop<Self>>>
  • Pin<Arc<ManuallyDrop<Self>>>

This is similar to but distinct from #56193, which is about making coercions valid involving a manually drop wrapped around a pointer type.

In particular, I am personally interested in having Pin<&mut ManuallyDrop<Self>> as a dyn-compatible receiver type for an unsafe trait method in my code, as it assists users in understanding the guarantees the caller is giving them - that it will never access or move this value again, even to drop it, do with that what you will.

cc @mikeyhew @rust-lang/lang @rust-lang/wg-unsafe-code-guidelines

Footnotes

  1. Formerly known as "object safe".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutF-arbitrary_self_types`#![feature(arbitrary_self_types)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions