Skip to content

Commit e821b9c

Browse files
committed
Use to format empty structs comments
1 parent aa82620 commit e821b9c

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

src/items.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,32 +1422,26 @@ fn format_empty_struct_or_tuple(
14221422
result.push_str(&offset.to_string_with_newline(context.config))
14231423
}
14241424
result.push_str(opener);
1425-
match rewrite_missing_comment(span, Shape::indented(offset, context.config), context) {
1426-
Some(ref s) if s.is_empty() => (),
1427-
Some(ref s) => {
1428-
if !is_single_line(s) || first_line_contains_single_line_comment(s) {
1429-
// Indent every comment line
1430-
for l in s.lines() {
1431-
if l.trim_start().starts_with("//") {
1432-
let nested_indent_str = offset
1433-
.block_indent(context.config)
1434-
.to_string_with_newline(context.config);
1435-
result.push_str(&nested_indent_str);
1436-
} else {
1437-
result.push('\n');
1438-
}
1439-
result.push_str(l);
1440-
}
1441-
} else {
1442-
result.push_str(s);
1443-
}
14441425

1445-
if last_line_contains_single_line_comment(s) {
1446-
result.push_str(&offset.to_string_with_newline(context.config));
1447-
}
1426+
let mut visitor = FmtVisitor::from_context(context);
1427+
let item_indent = offset.block_only().block_indent(context.config);
1428+
visitor.block_indent = item_indent.clone();
1429+
visitor.last_pos = span.lo();
1430+
1431+
visitor.format_missing_no_indent(span.hi());
1432+
1433+
if !is_empty_line(&visitor.buffer) {
1434+
if is_single_line(visitor.buffer.trim()) {
1435+
result.push_str(&format!(
1436+
"\n{}{}\n",
1437+
item_indent.to_string(context.config),
1438+
visitor.buffer.trim()
1439+
));
1440+
} else {
1441+
result.push_str(&visitor.buffer);
14481442
}
1449-
None => result.push_str(context.snippet(span)),
14501443
}
1444+
14511445
result.push_str(closer);
14521446
}
14531447

tests/source/structs.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,23 @@ struct CommentsTup(
313313
// With break
314314
// Yes
315315
);
316+
317+
struct CommentsBlock {
318+
/* some block
319+
that is some block
320+
- a
321+
- b
322+
- c
323+
*/ }
324+
325+
struct TupleWithBlock(
326+
/* abcd
327+
* efg
328+
*/
329+
);
330+
331+
struct TupleWithBlockIndent(
332+
/* abcd
333+
* efg
334+
*/
335+
);

tests/target/structs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,21 @@ struct CommentsTup(
373373
// With break
374374
// Yes
375375
);
376+
377+
struct CommentsBlock {
378+
// some block
379+
// that is some block
380+
// - a
381+
// - b
382+
// - c
383+
}
384+
385+
struct TupleWithBlock(
386+
// abcd
387+
// efg
388+
);
389+
390+
struct TupleWithBlockIndent(
391+
// abcd
392+
// efg
393+
);

0 commit comments

Comments
 (0)