Skip to content

Tracking Issue for Transmutability Trait: #[transmutability] #99571

Open
@jswrenn

Description

Feature gate: #![feature(transmutability)]

This is a tracking issue for MCP411: Lang Item for Transmutability. The MCP defines an experimental, compiler-implemented trait that can be used to audit whether a particular transmutation (or other form of bit-reinterpretation cast) is safe.

At this time, this feature is NOT on track to stabilization. It has been specified in an MCP, not an RFC, and will likely require an RFC to be tracked for stabilization.

Public API

The public API of this feature (which may have evolved since this issue's last update), is roughly as follows:

pub unsafe trait TransmuteFrom<Src, const ASSUME: Assume = { Assume::NOTHING }>
where
    Src: ?Sized,
{
    unsafe fn transmute(src: Src) -> Self
    where
        Src: Sized,
        Self: Sized,
    {
        ...
    }
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct Assume {
    pub alignment: bool,
    pub lifetimes: bool,
    pub safety: bool,
    pub validity: bool,
}

impl Assume {
    pub const NOTHING: Self =
        Self { alignment: false, lifetimes: false, safety: false, validity: false };

    pub const ALIGNMENT: Self = Self { alignment: true, ..Self::NOTHING };
    pub const LIFETIMES: Self = Self { lifetimes: true, ..Self::NOTHING };
    pub const SAFETY: Self = Self { safety: true, ..Self::NOTHING };
    pub const VALIDITY: Self = Self { validity: true, ..Self::NOTHING };

    pub const fn and(self, other_assumptions: Self) -> Self { ... }
    pub const fn but_not(self, other_assumptions: Self) -> Self { ... }
}

Steps / History

Unresolved Questions

Virtually all aspects of this experimental feature are unresolved.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-transmutability`#![feature(transmutability)]`T-libs-apiRelevant to the library API 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