diff --git a/rustfmt-core/rustfmt-lib/src/missed_spans.rs b/rustfmt-core/rustfmt-lib/src/missed_spans.rs index 92fcb000ff9..6c326bffa48 100644 --- a/rustfmt-core/rustfmt-lib/src/missed_spans.rs +++ b/rustfmt-core/rustfmt-lib/src/missed_spans.rs @@ -48,6 +48,12 @@ impl<'a> FmtVisitor<'a> { self.last_pos = end; return; } + + let last_line_str = self.buffer.lines().last().unwrap_or(""); + if !missing_snippet.starts_with("\n") && last_line_str.find("//").is_some() { + self.push_str("\n"); + } + self.format_missing_inner(end, |this, last_snippet, _| this.push_str(last_snippet)) } diff --git a/rustfmt-core/rustfmt-lib/tests/source/issue-3988.rs b/rustfmt-core/rustfmt-lib/tests/source/issue-3988.rs new file mode 100644 index 00000000000..f56290a1522 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/source/issue-3988.rs @@ -0,0 +1,9 @@ +// rustfmt-normalize_doc_attributes: true +// rustfmt-max_width: 10 + +mod a { + mod b { + #[doc = "test"]fn foo() -> () { + } + } +} diff --git a/rustfmt-core/rustfmt-lib/tests/target/issue-3988.rs b/rustfmt-core/rustfmt-lib/tests/target/issue-3988.rs new file mode 100644 index 00000000000..8a1e830298e --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/target/issue-3988.rs @@ -0,0 +1,10 @@ +// rustfmt-normalize_doc_attributes: true +// rustfmt-max_width: 10 + +mod a { + mod b { + ///test +fn foo() -> (){ + } + } +}