Skip to content

ptr-meta: DynMetadata and Pointee::Metadata are not UnwindSafe #86235

Open
@nwsharp

Description

@nwsharp

DynMetadata is only UnwindSafe if its Dyn type argument is as well. This is a bit strange as DynMetadata is, data-wise, just a &'static to an immutable virtual table. There's not a way to observe broken invariant involving such a reference unless somehow the shared library containing the vtable is unloaded -- which violates 'static, would be super-mega-bad, and probably shouldn't be happening during unwind.

https://rust-lang.github.io/rfcs/2580-ptr-meta.html (#81513) states that Pointee::Metadata is Copy + Send + Sync + Ord + Hash + Unpin. Given these constraints, as well as the current types being (), usize, and DynMetadata, it seems reasonable to me that Pointee::Metadata also therefore be UnwindSafe.

I understand that UnwindSafe is currently in std, but with #84662 it will move into libcore. Provided that we indeed want it as a bound of Pointee::Metadata, we should definitely land this before exposing the ability for users to create custom metadata types.

Changing the bounds on Pointee::Metadata is explicitly mentioned as a concern in these meeting minutes.

(Also, the shared library unloading thing may indicate that we may want to drop the &'static in favor of *const.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)A-lang-itemArea: Language itemsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions