Skip to content

Support prefix transmutes in transmute! et al #1852

@joshlf

Description

@joshlf

Syntax

We should be able to add special syntax so that existing uses of transmute! are unaffected, while users are able to opt-in to prefix transmute behavior:

// Current behavior, remains the default.
transmute!(a);
// Opt-in to prefix transmutation (exact syntax to be bikeshedded)
transmute!(@prefix a);

Design

Currently, we require that mem::transmute::<T, U>() compiles, which ensures that size_of::<T>() == size_of::<U>(). If we instead introduce a union MaxSizesOf<T, U> type, then we can instead require that mem::transmute::<MaxSizesOf<T, U>, T>() compiles. This ensures that size_of::<T>() >= size_of::<U>(), which ensures that it's sound to perform a prefix transmute from T to U.

Metadata

Metadata

Assignees

No one assigned

    Labels

    experience-hardThis issue is hard, and requires a lot of experiencehelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions