Repository navigation
Tracking Issue for Transmutability Trait: #[transmutability] #99571
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-transmutability`#![feature(transmutability)]``#![feature(transmutability)]`T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
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
- MCP: Lang Item for Transmutability compiler-team#411
- Implementation:
- RFC: #...
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
Virtually all aspects of this experimental feature are unresolved.
- What can we transmute to and from a union?
- Naming of fields:
- What kind of transmute to model?
- Is the transmute-via-union example fully specified?
- How do we ensure that we can still change rustc layout details without this resulting in things breaking?
- See https://github.com/rust-lang/rust/pull/155473/changes#diff-03c9016a41f6f6eb195211d7697452d58120fccdfe56511025a478a33ea6f28c for example where changing how
repr(Rust)picks niche encodings needed to update transmutability tests.
- See https://github.com/rust-lang/rust/pull/155473/changes#diff-03c9016a41f6f6eb195211d7697452d58120fccdfe56511025a478a33ea6f28c for example where changing how
- Should
Assumebe#[non_exhaustive]? Or not have public fields? In case we want to adapt to more fine or coarse assumptions in the future.
Footnotes
Reacted by Till Ulen, vulpine and Cherry
Reacted by Wanja Hentze, Nicholas Hein, Cherry and Koutheir A.
Reacted by decorator-factory, Maaz Ahmed and Cherry
Reacted by Aurelia Molzer, Kisaragi, José Luis Cruz, Tobbelowski, João Marcos, orzogc, Ido Ben Amram, Caio, Aleksandr Fedorov, Lily and 2 more
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-transmutability`#![feature(transmutability)]``#![feature(transmutability)]`T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
Rollup merge of rust-lang#100726 - jswrenn:transmute, r=oli-obk
Auto merge of rust-lang#100726 - jswrenn:transmute, r=oli-obk
safe transmute: use `Assume` struct to provide analysis options
Auto merge of #100726 - jswrenn:transmute, r=oli-obk
Auto merge of #100726 - jswrenn:transmute, r=oli-obk
Auto merge of #100726 - jswrenn:transmute, r=oli-obk
Rollup merge of rust-lang#129217 - jswrenn:transmute-lifetimes, r=com…
Unrolled build for rust-lang#129217
Rollup merge of rust-lang#129364 - jswrenn:transmute-layout-errs, r=c…
Unrolled build for rust-lang#129364
Rollup merge of rust-lang#129032 - jswrenn:transmute-method, r=compil…
Rollup merge of rust-lang#129032 - jswrenn:transmute-method, r=compil…
Unrolled build for rust-lang#129032
Rollup merge of rust-lang#129657 - jswrenn:transmute-name, r=compiler…
Unrolled build for rust-lang#129657
Rollup merge of #129657 - jswrenn:transmute-name, r=compiler-errors
Auto merge of #100726 - jswrenn:transmute, r=oli-obk