From afffea879f10d79ad2cf77f0cd12138f9ce94768 Mon Sep 17 00:00:00 2001 From: Andrey Manzharov Date: Mon, 2 Sep 2019 16:00:58 +0300 Subject: [PATCH 1/2] do not remove discriminant value if exists (#3771) --- src/items.rs | 32 ++++++++++++++------------------ tests/source/enum.rs | 8 ++++++++ tests/target/enum.rs | 13 +++++++++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/items.rs b/src/items.rs index bdae2eaafc6..0943122b090 100644 --- a/src/items.rs +++ b/src/items.rs @@ -557,24 +557,20 @@ impl<'a> FmtVisitor<'a> { self.block_indent, Some(one_line_width), )?, - ast::VariantData::Unit(..) => { - if let Some(ref expr) = field.node.disr_expr { - let lhs = format!( - "{:1$} =", - rewrite_ident(&context, field.node.ident), - pad_discrim_ident_to - ); - rewrite_assign_rhs_with( - &context, - lhs, - &*expr.value, - shape, - RhsTactics::AllowOverflow, - )? - } else { - rewrite_ident(&context, field.node.ident).to_owned() - } - } + ast::VariantData::Unit(..) => rewrite_ident(&context, field.node.ident).to_owned(), + }; + + let variant_body = if let Some(ref expr) = field.node.disr_expr { + let lhs = format!("{:1$} =", variant_body, pad_discrim_ident_to); + rewrite_assign_rhs_with( + &context, + lhs, + &*expr.value, + shape, + RhsTactics::AllowOverflow, + )? + } else { + variant_body }; combine_strs_with_missing_comments(&context, &attrs_str, &variant_body, span, shape, false) diff --git a/tests/source/enum.rs b/tests/source/enum.rs index fd563206ae5..0ed9651abe7 100644 --- a/tests/source/enum.rs +++ b/tests/source/enum.rs @@ -202,3 +202,11 @@ enum PublishedFileVisibility { FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly, Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate, } + +// #3771 +//#![feature(arbitrary_enum_discriminant)] +#[repr(u32)] +pub enum E { + A { a: u32 } = 0x100, + B { field1: u32, field2: u8, field3: m::M } = 0x300 // comment +} diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 6af05cbed90..179cc258927 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -273,3 +273,16 @@ enum PublishedFileVisibility { Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate, } + +//#![feature(arbitrary_enum_discriminant)] +#[repr(u32)] +pub enum E { + A { + a: u32, + } = 0x100, + B { + field1: u32, + field2: u8, + field3: m::M, + } = 0x300, // comment +} From 4e08c506e3e99d5e0a038806e16a317e40b6fe5d Mon Sep 17 00:00:00 2001 From: Andrey Manzharov Date: Mon, 2 Sep 2019 17:05:51 +0300 Subject: [PATCH 2/2] fix issue reference in test target --- tests/target/enum.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 179cc258927..9a25126b44e 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -274,6 +274,7 @@ enum PublishedFileVisibility { sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate, } +// #3771 //#![feature(arbitrary_enum_discriminant)] #[repr(u32)] pub enum E {