Closed
Description
repr(transparent)
exists which makes it safe to cast references between e.g. MaybeUninit<T>
and T
Does this extend to repr(Rust)
types containing repr(transparent)
? I.e., are we guaranteed that the following pairs of types:
struct Struct {
x: String,
y: Foo
}
struct StructUninit {
x: String,
y: MaybeUninit<Foo>
}
enum Enum {
A(String),
B(Foo, String)
}
enum EnumUninit {
A(String),
B(MaybeUninit<Foo>, String)
}
are fully layout compatible? The primary guarantee of repr(transparent)
is that it does not affect the size and alignment, but my understanding is that at the moment repr(Rust)
has no guarantees; it would be legal for repr(Rust)
to say "add a padding of 2 in every field whose type starts with an 'M'".
This guarantee would be very nice to have; because otherwise there's no way to do in-place initialization of Rust enums without repr(C)
.
cc @rust-lang/lang (unsure if this is the right place to file this)
Metadata
Metadata
Assignees
Labels
No labels