Skip to content

Commit 8f4680e

Browse files
authored
Rollup merge of #95804 - GuillaumeGomez:empty-doc-comment-with-backline, r=notriddle
rustdoc: Fix empty doc comment with backline ICE Fixes #95800. r? ```@notriddle```
2 parents 747bd16 + 5e8bd9b commit 8f4680e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

compiler/rustc_ast/src/util/comments.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
5252
// when we try to compute the "horizontal trim".
5353
let lines = if kind == CommentKind::Block {
5454
// Whatever happens, we skip the first line.
55-
let mut i = if lines[0].trim_start().starts_with('*') { 0 } else { 1 };
55+
let mut i = lines
56+
.get(0)
57+
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
58+
.unwrap_or(0);
5659
let mut j = lines.len();
5760

5861
while i < j && lines[i].trim().is_empty() {

src/test/rustdoc/empty-doc-comment.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Ensure that empty doc comments don't panic.
2+
3+
/*!
4+
*/
5+
6+
///
7+
///
8+
pub struct Foo;
9+
10+
#[doc = "
11+
"]
12+
pub mod Mod {
13+
//!
14+
//!
15+
}
16+
17+
/**
18+
*/
19+
pub mod Another {
20+
#![doc = "
21+
"]
22+
}

0 commit comments

Comments
 (0)