Skip to content

Commit

Permalink
Rollup merge of #90657 - GuillaumeGomez:one-char-last-line-removed, r…
Browse files Browse the repository at this point in the history
…=jyn514

Fix bug with `#[doc]` string single-character last lines

Fixes #90618.

This is because `.iter().all(|c| c == '*')` returns `true` if there is no character checked. And in case the last line has only one character, it simply returns `true`, making the last line behind removed.
  • Loading branch information
matthiaskrgr authored Nov 8, 2021
2 parents a01c667 + aa6f6f4 commit 4412b4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
i += 1;
}
// like the first, a last line of all stars should be omitted
if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') {
if j > i && !lines[j - 1].is_empty() && lines[j - 1].chars().all(|c| c == '*') {
j -= 1;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc/include_str_cut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name = "foo"]
#![no_std]

// @has 'foo/fn.foo.html'
// @has - '//*[@class="docblock"]' 'inc2 x'
#[doc = include_str!("short-line.md")]
pub fn foo() {}
2 changes: 2 additions & 0 deletions src/test/rustdoc/short-line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inc2
x

0 comments on commit 4412b4b

Please sign in to comment.