]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_ast/src/util/comments.rs
Fix invalid array access in `beautify_doc_string`
[rust.git] / compiler / rustc_ast / src / util / comments.rs
index f51b0086dc8b6d6be5b784c677f93c067505428c..8730aeb0f3bffdf182cef918a75c06a4a44bd391 100644 (file)
@@ -52,7 +52,10 @@ fn get_horizontal_trim<'a>(lines: &'a [&str], kind: CommentKind) -> Option<Strin
         // when we try to compute the "horizontal trim".
         let lines = if kind == CommentKind::Block {
             // Whatever happens, we skip the first line.
-            let mut i = if lines[0].trim_start().starts_with('*') { 0 } else { 1 };
+            let mut i = lines
+                .get(0)
+                .map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
+                .unwrap_or(0);
             let mut j = lines.len();
 
             while i < j && lines[i].trim().is_empty() {