Skip to content

Commit d20affb

Browse files
authored
Rollup merge of #92357 - GuillaumeGomez:fix-doc-comment-backline-removal, r=camelid
Fix invalid removal of newlines from doc comments Fixes #91201. Before: ![Screenshot from 2021-12-28 17-02-11](https://user-images.githubusercontent.com/3050060/147585187-c8e67531-c1b4-457d-9d30-d5b44bf91fea.png) After: ![Screenshot from 2021-12-28 17-02-25](https://user-images.githubusercontent.com/3050060/147585190-30aa0398-1fc7-4fe7-9e8b-5c475d4f9613.png) r? `@camelid`
2 parents 6466f89 + c6ee7bb commit d20affb

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

compiler/rustc_ast/src/util/comments.rs

-7
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,11 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
3434
i += 1;
3535
}
3636

37-
while i < j && lines[i].trim().is_empty() {
38-
i += 1;
39-
}
4037
// like the first, a last line of all stars should be omitted
4138
if j > i && !lines[j - 1].is_empty() && lines[j - 1].chars().all(|c| c == '*') {
4239
j -= 1;
4340
}
4441

45-
while j > i && lines[j - 1].trim().is_empty() {
46-
j -= 1;
47-
}
48-
4942
if i != 0 || j != lines.len() { Some((i, j)) } else { None }
5043
}
5144

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="docblock"><p>Hello world!
2-
Goodbye!
1+
<div class="docblock"><p>Hello world!</p>
2+
<p>Goodbye!
33
Hello again!</p>
44
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="docblock"><p>Par 1</p>
2+
<p>Par 2</p>
3+
</div>

src/test/rustdoc/mixing-doc-comments-and-attrs.rs

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ pub struct S1;
1616
#[doc = "Goodbye!"]
1717
/// Hello again!
1818
pub struct S2;
19+
20+
// @has 'foo/struct.S3.html'
21+
// @snapshot S3_top-doc - '//details[@class="rustdoc-toggle top-doc"]/div[@class="docblock"]'
22+
/** Par 1
23+
*/ ///
24+
/// Par 2
25+
pub struct S3;

0 commit comments

Comments
 (0)