* Fix #1258

* Add test
This commit is contained in:
sinkuu 2017-01-09 12:11:12 +09:00 committed by Nick Cameron
parent ad46f9af95
commit 7e2fcc27e1
3 changed files with 31 additions and 1 deletions

View File

@ -839,7 +839,18 @@ fn format_struct_struct(context: &RewriteContext,
// FIXME(#919): properly format empty structs and their comments.
if fields.is_empty() {
result.push_str(&context.snippet(mk_sp(body_lo, span.hi)));
let snippet = context.snippet(mk_sp(body_lo, span.hi - BytePos(1)));
if snippet.trim().is_empty() {
// `struct S {}`
} else if snippet.trim_right_matches(&[' ', '\t'][..]).ends_with('\n') {
// fix indent
result.push_str(&snippet.trim_right());
result.push('\n');
result.push_str(&offset.to_string(context.config));
} else {
result.push_str(&snippet);
}
result.push('}');
return Some(result);
}

View File

@ -153,4 +153,15 @@ struct Issue677 {
}
struct Foo {}
struct Foo {
}
struct Foo {
// comment
}
struct Foo {
// trailing space ->
}
struct Foo { /* comment */ }
struct Foo();

View File

@ -161,4 +161,12 @@ struct Issue677 {
}
struct Foo {}
struct Foo {}
struct Foo {
// comment
}
struct Foo {
// trailing space ->
}
struct Foo { /* comment */ }
struct Foo();