Merge pull request #866 from rust-lang-nursery/empty-extern

Keep empty extern blocks on one line
This commit is contained in:
Marcus Klaas de Vries 2016-03-16 18:06:25 +01:00
commit 6f2bb908bb
3 changed files with 20 additions and 9 deletions

View File

@ -84,19 +84,24 @@ impl<'a> FmtVisitor<'a> {
self.buffer.push_str(&::utils::format_abi(fm.abi));
let snippet = self.snippet(span);
let brace_pos = snippet.find_uncommented("{").unwrap() as u32;
let brace_pos = snippet.find_uncommented("{").unwrap();
// FIXME: this skips comments between the extern keyword and the opening
// brace.
self.last_pos = span.lo + BytePos(brace_pos);
self.block_indent = self.block_indent.block_indent(self.config);
if fm.items.is_empty() && !contains_comment(&snippet[brace_pos..]) {
self.buffer.push_str("{");
} else {
// FIXME: this skips comments between the extern keyword and the opening
// brace.
self.last_pos = span.lo + BytePos(brace_pos as u32);
self.block_indent = self.block_indent.block_indent(self.config);
for item in &fm.items {
self.format_foreign_item(&*item);
for item in &fm.items {
self.format_foreign_item(&*item);
}
self.block_indent = self.block_indent.block_unindent(self.config);
self.format_missing_with_indent(span.hi - BytePos(1));
}
self.block_indent = self.block_indent.block_unindent(self.config);
self.format_missing_with_indent(span.hi - BytePos(1));
self.buffer.push_str("}");
self.last_pos = span.hi;
}

View File

@ -34,3 +34,7 @@ libc::c_long;
file: *mut FILE)
-> *mut FILE;
}
extern {
}

View File

@ -45,3 +45,5 @@ extern "C" {
file: *mut FILE)
-> *mut FILE;
}
extern "C" {}