Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does T and U having the same layout mean that Foo<T> and Foo<U> have the same layout? #1019

Open
Ekleog opened this issue May 7, 2021 · 0 comments
Labels
A-type-layout Area: type layout

Comments

@Ekleog
Copy link

Ekleog commented May 7, 2021

Hey!

I'm not sure whether here is the right place to open this issue, but I've been in a discussion with @nox about the things that are allowed with repr(transparent) structs.

In particular, suppose this code:

struct Foo<T>(T);
struct Bar;
#[repr(transparent)] struct Baz(Bar);

fn foo(x: Foo<Bar>) -> Foo<Baz> {
    unsafe { std::mem::transmute(x) }
}

Is it correct? In other words, is Foo<T> guaranteed to have the same layout as Foo<U> if T has the same layout as U? (knowing that Foo is repr(Rust))

I'm thinking the answer to this question should be added to the repr(transparent) part of the reference, but I couldn't find the answer in the related RFC; so I couldn't find an answer to this question.

Is the answer to the question known? (In practice it is to the best of my knowledge currently the same layout, but I don't know whether it is a guarantee given for the foreseeable future)

@Ekleog Ekleog changed the title Does T and U having the same layout meen that Foo<T> and Foo<U> have the same layout? Does T and U having the same layout mean that Foo<T> and Foo<U> have the same layout? May 7, 2021
@ehuss ehuss added the A-type-layout Area: type layout label Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-layout Area: type layout
Projects
None yet
Development

No branches or pull requests

2 participants