Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 72ca0e5

Browse files
authored
Merge pull request rust-lang#3577 from topecongiro/issue-3575
Insert an empty line when normalizing `#[doc = ""]`
2 parents 86dad6e + bdb7223 commit 72ca0e5

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/attr/doc_comment.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ impl Display for DocCommentFormatter<'_> {
1212
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1313
let opener = self.style.opener().trim_end();
1414
let mut lines = self.literal.lines().peekable();
15+
16+
// Handle `#[doc = ""]`.
17+
if lines.peek().is_none() {
18+
return write!(formatter, "{}", opener);
19+
}
20+
1521
while let Some(line) = lines.next() {
1622
let is_last_line = lines.peek().is_none();
1723
if is_last_line {

tests/source/normalize_multiline_doc_attribute.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
is split
66
on multiple lines"]
77
fn foo() {}
8+
9+
#[doc = " B1"]
10+
#[doc = ""]
11+
#[doc = " A1"]
12+
fn bar() {}

tests/target/normalize_multiline_doc_attribute.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
///is split
66
///on multiple lines
77
fn foo() {}
8+
9+
/// B1
10+
///
11+
/// A1
12+
fn bar() {}

0 commit comments

Comments
 (0)