Skip to content

Commit 83290f1

Browse files
committed
Add comma after struct-like enum variant
This is mandatory.
1 parent fc44837 commit 83290f1

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/items.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a> FmtVisitor<'a> {
427427

428428
self.format_missing_with_indent(field.span.lo);
429429

430-
match field.node.kind {
430+
let result = match field.node.kind {
431431
ast::VariantKind::TupleVariantKind(ref types) => {
432432
let vis = format_visibility(field.node.vis);
433433
self.changes.push_str_span(field.span, vis);
@@ -482,23 +482,23 @@ impl<'a> FmtVisitor<'a> {
482482
"Enum variant exceeded column limit");
483483
}
484484

485-
self.changes.push_str_span(field.span, &result);
486-
487-
if !last_field || self.config.enum_trailing_comma {
488-
self.changes.push_str_span(field.span, ",");
489-
}
485+
result
490486
},
491487
ast::VariantKind::StructVariantKind(ref struct_def) => {
492-
let result = self.format_struct("",
493-
field.node.name,
494-
field.node.vis,
495-
struct_def,
496-
None,
497-
field.span,
498-
self.block_indent);
499-
500-
self.changes.push_str_span(field.span, &result)
488+
// TODO Should limit the width, as we have a trailing comma
489+
self.format_struct("",
490+
field.node.name,
491+
field.node.vis,
492+
struct_def,
493+
None,
494+
field.span,
495+
self.block_indent)
501496
}
497+
};
498+
self.changes.push_str_span(field.span, &result);
499+
500+
if !last_field || self.config.enum_trailing_comma {
501+
self.changes.push_str_span(field.span, ",");
502502
}
503503

504504
self.last_pos = field.span.hi + BytePos(1);

tests/target/enum.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ enum StructLikeVariants {
4040
// Pre-comment
4141
#[Attr50]
4242
y: SomeType, // Aanother Comment
43-
}
43+
},
44+
SL {
45+
a: A,
46+
},
4447
}

0 commit comments

Comments
 (0)