Skip to content

transmutability: unexpected behaviour when both init and uninit transitions are present #140337

@tmiasko

Description

@tmiasko
#![feature(transmutability)]
use std::mem::{Assume, MaybeUninit, TransmuteFrom};

pub fn is_transmutable<Src, Dst>() where Dst: TransmuteFrom<Src, { Assume::SAFETY }>{}

#[derive(Copy, Clone)]
#[repr(u8)]
enum B0 { Value = 0 }

#[derive(Copy, Clone)]
#[repr(u8)]
enum B1 { Value = 1 }

fn main() {
    is_transmutable::<(B0, B0), MaybeUninit<(B0, B0)>>(); // ok
    is_transmutable::<(B0, B0), MaybeUninit<(B0, B1)>>(); // unexpected error: `(B0, B0)` cannot be safely transmuted into `MaybeUninit<(B0, B1)>`
    is_transmutable::<(B0, B0), MaybeUninit<(B1, B0)>>(); // ok
    is_transmutable::<(B0, B0), MaybeUninit<(B1, B1)>>(); // ok
}

cc @jswrenn

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-transmutability`#![feature(transmutability)]`T-compilerRelevant to the compiler 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