Skip to content

Commit 4488e40

Browse files
authored
Use the correct shape when formatting comment in empty struct (#4058)
1 parent bfec1e9 commit 4488e40

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

rustfmt-core/rustfmt-lib/src/items.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,9 @@ fn format_empty_struct_or_tuple(
14411441
result.push_str(&offset.to_string_with_newline(context.config))
14421442
}
14431443
result.push_str(opener);
1444-
match rewrite_missing_comment(span, Shape::indented(offset, context.config), context) {
1444+
let comment_shape =
1445+
Shape::indented(offset, context.config).block_indent(context.config.tab_spaces());
1446+
match rewrite_missing_comment(span, comment_shape, context) {
14451447
Some(ref s) if s.is_empty() => (),
14461448
Some(ref s) => {
14471449
if !is_single_line(s) || first_line_contains_single_line_comment(s) {

rustfmt-core/rustfmt-lib/tests/source/structs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,9 @@ struct Test {
285285
// #2818
286286
struct Paren((i32)) where i32: Trait;
287287
struct Parens((i32, i32)) where i32: Trait;
288+
289+
// #4014
290+
struct X {
291+
// foo
292+
// bar
293+
}

rustfmt-core/rustfmt-lib/tests/target/structs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,9 @@ where
342342
struct Parens((i32, i32))
343343
where
344344
i32: Trait;
345+
346+
// #4014
347+
struct X {
348+
// foo
349+
// bar
350+
}

0 commit comments

Comments
 (0)