Skip to content

Commit

Permalink
do not remove discriminant value if exists (#3771) (#3772)
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-afk authored and topecongiro committed Sep 4, 2019
1 parent 2bf67b6 commit 950b288
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/source/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions tests/target/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,17 @@ enum PublishedFileVisibility {
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
}

0 comments on commit 950b288

Please sign in to comment.