Skip to content

How far does repr(transparent)'s transparentness stretch in repr(Rust)? #604

@Manishearth

Description

@Manishearth

As I understand it, generally two otherwise identical Rust type definitions (e.g. struct Foo(u8, usize), struct Bar(u8, usize)) do not need to produce transmutable types, trivially shown by using -Zrandomize-layout with identically defined structs with a couple fields.

However, of course (u8, usize) and (u8, usize) can be transmuted, after all, they are the same type. The same goes for Generic<u8> and Generic<u8>.

What if we have #[repr(transparent)] struct Wrap(u8);: Are (Wrap, usize) and (u8, usize) transmutable?

What about Generic<u8> and Generic<Wrap> where Generic is some generic struct?

How far does repr(transparent) stretch in its equivalency when the transparent type is used as a field elsewhere?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutTopic: Related to data structure layout (`#[repr]`)S-not-opsemDespite being in this repo, this is not primarily a T-opsem question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions