Skip to content

Commit

Permalink
Add link to RFC 2915 for data-ful enums with reprs
Browse files Browse the repository at this point in the history
and clarify which attribute is being referred to in the next paragraph.
  • Loading branch information
zachs18 committed Aug 8, 2024
1 parent b509ff2 commit f02ae6f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0517.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ of the enum to the size of the provided type. Such an enum can be cast to a
value of the same type as well. In short, `#[repr(u8)]` makes a field-less enum
behave like an integer with a constrained set of allowed values.

Only field-less enums can be cast to numerical primitives. This attribute
will not apply to structs.
For a description of how `#[repr(C)]` and representations like `#[repr(u8)]`
affect the layout of enums with data fields, see [RFC 2915][rfc2915].

Only field-less enums can be cast to numerical primitives. Representations like
`#[repr(u8)]` will not apply to structs.

`#[repr(packed)]` reduces padding to make the struct size smaller. The
representation of enums isn't strictly defined in Rust, and this attribute
Expand All @@ -42,3 +45,5 @@ won't work on enums.
types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via
SIMD. This doesn't make much sense for enums since they don't consist of a
single list of data.

[rfc2915]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md

0 comments on commit f02ae6f

Please sign in to comment.