fix: resolve idempotency issue in extern body elements

This commit is contained in:
Caleb Cartwright 2021-09-07 19:49:56 -05:00 committed by Caleb Cartwright
parent 3d8cd57c2f
commit 57548aa096
3 changed files with 26 additions and 8 deletions

View file

@ -51,6 +51,14 @@ impl<'a> FmtVisitor<'a> {
}
pub(crate) fn format_missing_with_indent(&mut self, end: BytePos) {
self.format_missing_indent(end, true)
}
pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) {
self.format_missing_indent(end, false)
}
fn format_missing_indent(&mut self, end: BytePos, should_indent: bool) {
let config = self.config;
self.format_missing_inner(end, |this, last_snippet, snippet| {
this.push_str(last_snippet.trim_end());
@ -58,14 +66,10 @@ impl<'a> FmtVisitor<'a> {
// No new lines in the snippet.
this.push_str("\n");
}
if should_indent {
let indent = this.block_indent.to_string(config);
this.push_str(&indent);
})
}
pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) {
self.format_missing_inner(end, |this, last_snippet, _| {
this.push_str(last_snippet.trim_end());
})
}

View file

@ -0,0 +1,5 @@
mod test {
extern "C" {fn test();}
}
extern "C" {fn test();}

View file

@ -0,0 +1,9 @@
mod test {
extern "C" {
fn test();
}
}
extern "C" {
fn test();
}