Rollup merge of #95804 - GuillaumeGomez:empty-doc-comment-with-backline, r=notriddle

rustdoc: Fix empty doc comment with backline ICE

Fixes #95800.

r? ```@notriddle```
This commit is contained in:
Dylan DPC 2022-04-09 05:58:46 +02:00 committed by GitHub
commit 8f4680e37c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -52,7 +52,10 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
// 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() {

View File

@ -0,0 +1,22 @@
// Ensure that empty doc comments don't panic.
/*!
*/
///
///
pub struct Foo;
#[doc = "
"]
pub mod Mod {
//!
//!
}
/**
*/
pub mod Another {
#![doc = "
"]
}