From 2445f0ea763684939d87e567827e81656e646b5e Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 22 May 2019 00:10:35 +0900 Subject: [PATCH 1/2] Add a test for #3575 --- tests/source/normalize_multiline_doc_attribute.rs | 5 +++++ tests/target/normalize_multiline_doc_attribute.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/source/normalize_multiline_doc_attribute.rs b/tests/source/normalize_multiline_doc_attribute.rs index 91d930912444..3564e3e7ad05 100644 --- a/tests/source/normalize_multiline_doc_attribute.rs +++ b/tests/source/normalize_multiline_doc_attribute.rs @@ -5,3 +5,8 @@ is split on multiple lines"] fn foo() {} + +#[doc = " B1"] +#[doc = ""] +#[doc = " A1"] +fn bar() {} diff --git a/tests/target/normalize_multiline_doc_attribute.rs b/tests/target/normalize_multiline_doc_attribute.rs index 3b30525cacef..890c9bb20cd8 100644 --- a/tests/target/normalize_multiline_doc_attribute.rs +++ b/tests/target/normalize_multiline_doc_attribute.rs @@ -5,3 +5,8 @@ ///is split ///on multiple lines fn foo() {} + +/// B1 +/// +/// A1 +fn bar() {} From bdb72237a274a2edbe38b9e1ebae18c00ae3ae96 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 22 May 2019 00:10:46 +0900 Subject: [PATCH 2/2] Insert an empty line when normalizing `#[doc = ""]` --- src/attr/doc_comment.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/attr/doc_comment.rs b/src/attr/doc_comment.rs index 00185425d6a5..c3dcb84c9488 100644 --- a/src/attr/doc_comment.rs +++ b/src/attr/doc_comment.rs @@ -12,6 +12,12 @@ impl Display for DocCommentFormatter<'_> { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let opener = self.style.opener().trim_end(); let mut lines = self.literal.lines().peekable(); + + // Handle `#[doc = ""]`. + if lines.peek().is_none() { + return write!(formatter, "{}", opener); + } + while let Some(line) = lines.next() { let is_last_line = lines.peek().is_none(); if is_last_line {