The #[repr()] attribute can be given various options. It has the following inconsistent behavior when given duplicate attributes.
Multiple Rust reprs or multiple C reprs on structs are seemingly ignored.
Example
#[repr(Rust, Rust)]
struct Thing1(u8);
#[repr(C, C)]
struct Thing2(u8);
This code compiles without errors.
Multiple transparent reprs are a compile error.
Example
#[repr(transparent, transparent)]
struct Thing(u8);
Error:
error[E0692]: transparent struct cannot have other repr hints
--> src/lib.rs:1:8
|
1 | #[repr(transparent, transparent)]
| ^^^^^^^^^^^ ^^^^^^^^^^^
For more information about this error, try `rustc --explain E0692`.
Multiple align reprs are accepted. The greatest value is used as the actual alignment.
Example
#[repr(align(2), align(8), align(4))]
struct Thing(u8);
fn main() {
assert_eq!(align_of::<Thing>(), 8);
}
This code compiles and runs without errors.
Multiple packed reprs with the same alignment value are accepted.
Example
#[repr(packed(2), packed(2))]
struct Thing(u32);
fn main() {
assert_eq!(align_of::<Thing>(), 2);
}
This code compiles and runs without errors.
Multiple packed reprs with different alignment values are a compile error.
Example
#[repr(packed(2), packed(1))]
struct Thing(u32);
Error:
error[E0634]: type has conflicting packed representation hints
--> src/lib.rs:2:1
|
2 | struct Thing(u32);
| ^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0634`.
Multiple integer reprs on enums are a FCW deny-by-default lint. See #68585.
Example
#[repr(u8, u8)]
enum Thing {
Variant,
}
Error:
error[E0566]: conflicting representation hints
--> src/lib.rs:1:8
|
1 | #[repr(u8, u8)]
| ^^ ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default
Multiple Rust reprs or multiple C reprs on enums on their own are seemingly ignored.
Example
#[repr(Rust, Rust)]
enum Thing1 {
Variant(u8),
}
#[repr(C, C)]
enum Thing2 {
Variant(u8),
}
This code compiles without errors.
Multiple Rust reprs, when combined with an integer repr, are a compile error.
Example
#[repr(Rust, Rust, u8)]
enum Thing {
Variant(u8),
}
Error:
error[E0566]: conflicting representation hints
--> src/lib.rs:1:8
|
1 | #[repr(Rust, Rust, u8)]
| ^^^^ ^^^^ ^^
For more information about this error, try `rustc --explain E0566`.
Multiple C reprs, when combined with an integer repr, are seemingly ignored.
Example
#[repr(C, C, u8)]
enum Thing {
Variant(u8),
}
This code compiles without errors.
Multiple integer reprs, when combined with a Rust repr, emits the FCW in #68585, but also emits a hard error. (This hard error is not emitted when Rust is replaced with C.)
Example
#[repr(Rust, u8, u8)]
enum Thing {
Variant(u8),
}
Error:
error[E0566]: conflicting representation hints
--> src/lib.rs:1:8
|
1 | #[repr(Rust, u8, u8)]
| ^^^^ ^^ ^^
error[E0566]: conflicting representation hints
--> src/lib.rs:1:8
|
1 | #[repr(Rust, u8, u8)]
| ^^^^ ^^ ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default
For more information about this error, try `rustc --explain E0566`.
cc @JonathanBrouwer @jdonszelmann
Meta
Reproducible on the playground with version 1.97.0-nightly (2026-04-29 c935696dd07ca51e6fba)
The
#[repr()]attribute can be given various options. It has the following inconsistent behavior when given duplicate attributes.Multiple
Rustreprs or multipleCreprs on structs are seemingly ignored.Example
This code compiles without errors.
Multiple
transparentreprs are a compile error.Example
Error:
Multiple
alignreprs are accepted. The greatest value is used as the actual alignment.Example
This code compiles and runs without errors.
Multiple
packedreprs with the same alignment value are accepted.Example
This code compiles and runs without errors.
Multiple
packedreprs with different alignment values are a compile error.Example
Error:
Multiple integer reprs on enums are a FCW deny-by-default lint. See #68585.
Example
Error:
Multiple
Rustreprs or multipleCreprs on enums on their own are seemingly ignored.Example
This code compiles without errors.
Multiple
Rustreprs, when combined with an integer repr, are a compile error.Example
Error:
Multiple
Creprs, when combined with an integer repr, are seemingly ignored.Example
This code compiles without errors.
Multiple integer reprs, when combined with a
Rustrepr, emits the FCW in #68585, but also emits a hard error. (This hard error is not emitted whenRustis replaced withC.)Example
Error:
cc @JonathanBrouwer @jdonszelmann
Meta
Reproducible on the playground with version
1.97.0-nightly (2026-04-29 c935696dd07ca51e6fba)