Rollup merge of #128795 - zachs18:e0517-update-for-rfc-2195, r=jieyouxu

Update E0517 message to reflect RFC 2195.

E0517 occurs when a `#[repr(..)]` attribute is placed on an unsupported item. Currently, the explanation of the error implies that `#[repr(u*/i*)]` cannot be placed on fieldful enums, which is no longer the case since [RFC 2195](https://github.com/rust-lang/rfcs/pull/2195) was [stabilized](https://github.com/rust-lang/rust/issues/60553), which allows placing `#[repr(u*/i*)]` and/or `#[repr(C)]` on fieldful enums to produce a defined layout.

This PR doesn't (currently) add a description of the semantics of placing `#[repr(u*/i*)]` on a fieldful enum to the error explanation, it just removes the claims/implications that it is not allowed.
This commit is contained in:
Matthias Krüger 2024-08-08 18:57:02 +02:00 committed by GitHub
commit 25fc71b7a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,14 +25,17 @@ impl Foo {
These attributes do not work on typedefs, since typedefs are just aliases. These attributes do not work on typedefs, since typedefs are just aliases.
Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
discriminant size for enums with no data fields on any of the variants, e.g. discriminant size for enums. For enums with no data fields on any of the
`enum Color {Red, Blue, Green}`, effectively setting the size of the enum to variants, e.g. `enum Color {Red, Blue, Green}`, this effectively sets the size
the size of the provided type. Such an enum can be cast to a value of the same of the enum to the size of the provided type. Such an enum can be cast to a
type as well. In short, `#[repr(u8)]` makes the enum behave like an integer value of the same type as well. In short, `#[repr(u8)]` makes a field-less enum
with a constrained set of allowed values. behave like an integer with a constrained set of allowed values.
Only field-less enums can be cast to numerical primitives, so this attribute For a description of how `#[repr(C)]` and representations like `#[repr(u8)]`
will not apply to structs. affect the layout of enums with data fields, see [RFC 2195][rfc2195].
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 `#[repr(packed)]` reduces padding to make the struct size smaller. The
representation of enums isn't strictly defined in Rust, and this attribute representation of enums isn't strictly defined in Rust, and this attribute
@ -42,3 +45,5 @@ won't work on enums.
types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via 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 SIMD. This doesn't make much sense for enums since they don't consist of a
single list of data. single list of data.
[rfc2195]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md