Skip to content

Commit

Permalink
Rollup merge of rust-lang#95804 - GuillaumeGomez:empty-doc-comment-wi…
Browse files Browse the repository at this point in the history
…th-backline, r=notriddle

rustdoc: Fix empty doc comment with backline ICE

Fixes rust-lang#95800.

r? ``@notriddle``
  • Loading branch information
Dylan-DPC committed Apr 9, 2022
2 parents 192372e + 5e8bd9b commit 1769808
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/rustc_ast/src/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 22 additions & 0 deletions src/test/rustdoc/empty-doc-comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Ensure that empty doc comments don't panic.

/*!
*/

///
///
pub struct Foo;

#[doc = "
"]
pub mod Mod {
//!
//!
}

/**
*/
pub mod Another {
#![doc = "
"]
}

0 comments on commit 1769808

Please sign in to comment.