Skip to content

Use the correct shape when formatting comment in empty struct #4058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rustfmt-core/rustfmt-lib/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,9 @@ fn format_empty_struct_or_tuple(
result.push_str(&offset.to_string_with_newline(context.config))
}
result.push_str(opener);
match rewrite_missing_comment(span, Shape::indented(offset, context.config), context) {
let comment_shape =
Shape::indented(offset, context.config).block_indent(context.config.tab_spaces());
match rewrite_missing_comment(span, comment_shape, context) {
Some(ref s) if s.is_empty() => (),
Some(ref s) => {
if !is_single_line(s) || first_line_contains_single_line_comment(s) {
Expand Down
6 changes: 6 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/source/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,9 @@ struct Test {
// #2818
struct Paren((i32)) where i32: Trait;
struct Parens((i32, i32)) where i32: Trait;

// #4014
struct X {
// foo
// bar
}
6 changes: 6 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,9 @@ where
struct Parens((i32, i32))
where
i32: Trait;

// #4014
struct X {
// foo
// bar
}