Skip to content

Commit

Permalink
Use the correct shape when formatting comment in empty struct (rust-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro committed Feb 18, 2020
1 parent bfec1e9 commit 4488e40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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
}

0 comments on commit 4488e40

Please sign in to comment.