Skip to content

Commit 950b288

Browse files
iam-afktopecongiro
authored andcommitted
do not remove discriminant value if exists (rust-lang#3771) (rust-lang#3772)
1 parent 2bf67b6 commit 950b288

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/items.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -557,24 +557,20 @@ impl<'a> FmtVisitor<'a> {
557557
self.block_indent,
558558
Some(one_line_width),
559559
)?,
560-
ast::VariantData::Unit(..) => {
561-
if let Some(ref expr) = field.node.disr_expr {
562-
let lhs = format!(
563-
"{:1$} =",
564-
rewrite_ident(&context, field.node.ident),
565-
pad_discrim_ident_to
566-
);
567-
rewrite_assign_rhs_with(
568-
&context,
569-
lhs,
570-
&*expr.value,
571-
shape,
572-
RhsTactics::AllowOverflow,
573-
)?
574-
} else {
575-
rewrite_ident(&context, field.node.ident).to_owned()
576-
}
577-
}
560+
ast::VariantData::Unit(..) => rewrite_ident(&context, field.node.ident).to_owned(),
561+
};
562+
563+
let variant_body = if let Some(ref expr) = field.node.disr_expr {
564+
let lhs = format!("{:1$} =", variant_body, pad_discrim_ident_to);
565+
rewrite_assign_rhs_with(
566+
&context,
567+
lhs,
568+
&*expr.value,
569+
shape,
570+
RhsTactics::AllowOverflow,
571+
)?
572+
} else {
573+
variant_body
578574
};
579575

580576
combine_strs_with_missing_comments(&context, &attrs_str, &variant_body, span, shape, false)

tests/source/enum.rs

+8
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,11 @@ enum PublishedFileVisibility {
202202
FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly,
203203
Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate,
204204
}
205+
206+
// #3771
207+
//#![feature(arbitrary_enum_discriminant)]
208+
#[repr(u32)]
209+
pub enum E {
210+
A { a: u32 } = 0x100,
211+
B { field1: u32, field2: u8, field3: m::M } = 0x300 // comment
212+
}

tests/target/enum.rs

+14
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,17 @@ enum PublishedFileVisibility {
273273
Private =
274274
sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate,
275275
}
276+
277+
// #3771
278+
//#![feature(arbitrary_enum_discriminant)]
279+
#[repr(u32)]
280+
pub enum E {
281+
A {
282+
a: u32,
283+
} = 0x100,
284+
B {
285+
field1: u32,
286+
field2: u8,
287+
field3: m::M,
288+
} = 0x300, // comment
289+
}

0 commit comments

Comments
 (0)