Skip to content

Commit 43d0497

Browse files
Fix invalid array access in beautify_doc_string
1 parent 1a4b9a8 commit 43d0497

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-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() {

0 commit comments

Comments
 (0)