From ee97600a6f89963b08e1a16a36466a3d9b4783ba Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 28 Dec 2021 17:08:45 +0100 Subject: [PATCH 1/2] Fix invalid removal of backlines from doc comments --- compiler/rustc_ast/src/util/comments.rs | 7 ------- .../rustdoc/mixing-doc-comments-and-attrs.S1_top-doc.html | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_ast/src/util/comments.rs b/compiler/rustc_ast/src/util/comments.rs index 80a06fa594366..0a391123dd381 100644 --- a/compiler/rustc_ast/src/util/comments.rs +++ b/compiler/rustc_ast/src/util/comments.rs @@ -34,18 +34,11 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol { i += 1; } - while i < j && lines[i].trim().is_empty() { - i += 1; - } // like the first, a last line of all stars should be omitted if j > i && !lines[j - 1].is_empty() && lines[j - 1].chars().all(|c| c == '*') { j -= 1; } - while j > i && lines[j - 1].trim().is_empty() { - j -= 1; - } - if i != 0 || j != lines.len() { Some((i, j)) } else { None } } diff --git a/src/test/rustdoc/mixing-doc-comments-and-attrs.S1_top-doc.html b/src/test/rustdoc/mixing-doc-comments-and-attrs.S1_top-doc.html index 69d647a92e82b..8ff114b993edb 100644 --- a/src/test/rustdoc/mixing-doc-comments-and-attrs.S1_top-doc.html +++ b/src/test/rustdoc/mixing-doc-comments-and-attrs.S1_top-doc.html @@ -1,4 +1,4 @@ -

Hello world! -Goodbye! +

Hello world!

+

Goodbye! Hello again!

\ No newline at end of file From c6ee7bbe5197dbdec59acaab9b479f0610dfa5e1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 1 Jan 2022 11:04:44 +0100 Subject: [PATCH 2/2] Update mixed doc comments test --- .../rustdoc/mixing-doc-comments-and-attrs.S3_top-doc.html | 3 +++ src/test/rustdoc/mixing-doc-comments-and-attrs.rs | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 src/test/rustdoc/mixing-doc-comments-and-attrs.S3_top-doc.html diff --git a/src/test/rustdoc/mixing-doc-comments-and-attrs.S3_top-doc.html b/src/test/rustdoc/mixing-doc-comments-and-attrs.S3_top-doc.html new file mode 100644 index 0000000000000..a4ee4b1418637 --- /dev/null +++ b/src/test/rustdoc/mixing-doc-comments-and-attrs.S3_top-doc.html @@ -0,0 +1,3 @@ +

Par 1

+

Par 2

+
\ No newline at end of file diff --git a/src/test/rustdoc/mixing-doc-comments-and-attrs.rs b/src/test/rustdoc/mixing-doc-comments-and-attrs.rs index 1aedd4d107c21..a27c5ae6d0128 100644 --- a/src/test/rustdoc/mixing-doc-comments-and-attrs.rs +++ b/src/test/rustdoc/mixing-doc-comments-and-attrs.rs @@ -16,3 +16,10 @@ pub struct S1; #[doc = "Goodbye!"] /// Hello again! pub struct S2; + +// @has 'foo/struct.S3.html' +// @snapshot S3_top-doc - '//details[@class="rustdoc-toggle top-doc"]/div[@class="docblock"]' +/** Par 1 +*/ /// +/// Par 2 +pub struct S3;