From cf14b1760f747d94b1bfed2e5f937ce26320b987 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Nov 2017 10:55:40 -0700 Subject: [PATCH 1/6] Rename C-like enum to Field-less enum There is no need to reference the C programming language to explain this concept. --- src/test/parse-fail/tag-variant-disr-non-nullary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/parse-fail/tag-variant-disr-non-nullary.rs b/src/test/parse-fail/tag-variant-disr-non-nullary.rs index f90b1cc94bb..2d86589285c 100644 --- a/src/test/parse-fail/tag-variant-disr-non-nullary.rs +++ b/src/test/parse-fail/tag-variant-disr-non-nullary.rs @@ -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, From 8c9004630839888dd42595c9a481af1b7ae979bc Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Nov 2017 10:56:17 -0700 Subject: [PATCH 2/6] Update issue-17383.rs --- src/test/parse-fail/issue-17383.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/parse-fail/issue-17383.rs b/src/test/parse-fail/issue-17383.rs index 1b33cb38857..48f629fd828 100644 --- a/src/test/parse-fail/issue-17383.rs +++ b/src/test/parse-fail/issue-17383.rs @@ -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) } From a0628ef3d1c97f27d0a20995e6b32d841b78cf52 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Nov 2017 10:58:31 -0700 Subject: [PATCH 3/6] Update diagnostics.rs --- src/librustc/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index cba1a66c17c..eca64bfb5ec 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1641,13 +1641,13 @@ 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. +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 +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 From 06a75e4d1f472461ecdcb6baf24226f856379a41 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Nov 2017 10:59:14 -0700 Subject: [PATCH 4/6] Update parser.rs --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0b03429ea2e..3a71cff5968 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5891,7 +5891,7 @@ impl<'a> Parser<'a> { 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"), _ => () } From d6ba2e4d1cd5d857ff6318b715b9967d65cee181 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 6 Dec 2017 10:54:03 -0700 Subject: [PATCH 5/6] Fix dangling close paren --- src/librustc/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index eca64bfb5ec..02a4c8cfb87 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1642,7 +1642,7 @@ 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 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 +`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. From a126a732eb47dbd13b44452820a4d2b249330126 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 6 Dec 2017 10:54:50 -0700 Subject: [PATCH 6/6] Fix overlong line length --- src/librustc/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 02a4c8cfb87..591b800e241 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1647,8 +1647,8 @@ 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 field-less 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