Skip to content

Commit d9fc7d1

Browse files
Rollup merge of #90657 - GuillaumeGomez:one-char-last-line-removed, r=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.
2 parents 9318810 + aa6f6f4 commit d9fc7d1

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

compiler/rustc_ast/src/util/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
3838
i += 1;
3939
}
4040
// like the first, a last line of all stars should be omitted
41-
if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') {
41+
if j > i && !lines[j - 1].is_empty() && lines[j - 1].chars().all(|c| c == '*') {
4242
j -= 1;
4343
}
4444

src/test/rustdoc/include_str_cut.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name = "foo"]
2+
#![no_std]
3+
4+
// @has 'foo/fn.foo.html'
5+
// @has - '//*[@class="docblock"]' 'inc2 x'
6+
#[doc = include_str!("short-line.md")]
7+
pub fn foo() {}

src/test/rustdoc/short-line.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inc2
2+
x

0 commit comments

Comments
 (0)