提交 7b637b77 编写于 作者: B bors

Auto merge of #46187 - notriddle:patch-1, r=QuietMisdreavus

Rename C-like enum to Field-less enum

There is no need to reference the C programming language to explain this concept.
......@@ -1641,14 +1641,14 @@ impl Foo {
These attributes do not work on typedefs, since typedefs are just aliases.
Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
discriminant size for C-like enums (when there is no associated data, e.g.
`enum Color {Red, Blue, Green}`), effectively setting the size of the enum to
discriminant size for enums with no data fields on any of the variants, e.g.
`enum Color {Red, Blue, Green}`, effectively setting the size 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 the enum behave like an integer
with a constrained set of allowed values.
Only C-like enums can be cast to numerical primitives, so this attribute will
not apply to structs.
Only field-less enums can be cast to numerical primitives, so this attribute
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
......
......@@ -5995,7 +5995,7 @@ fn parse_enum_def(&mut self, _generics: &ast::Generics) -> PResult<'a, EnumDef>
match any_disr {
Some(disr_span) if !all_nullary =>
self.span_err(disr_span,
"discriminator values can only be used with a c-like enum"),
"discriminator values can only be used with a field-less enum"),
_ => ()
}
......
......@@ -12,7 +12,7 @@
enum X {
A =
b'a' //~ ERROR discriminator values can only be used with a c-like enum
b'a' //~ ERROR discriminator values can only be used with a field-less enum
,
B(isize)
}
......
......@@ -10,7 +10,7 @@
// compile-flags: -Z parse-only
//error-pattern: discriminator values can only be used with a c-like enum
//error-pattern: discriminator values can only be used with a field-less enum
enum color {
red = 0xff0000,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册