diff --git a/compiler/rustc_ast/src/util/comments.rs b/compiler/rustc_ast/src/util/comments.rs index 542a330a03141..c40aec4b671dd 100644 --- a/compiler/rustc_ast/src/util/comments.rs +++ b/compiler/rustc_ast/src/util/comments.rs @@ -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; } diff --git a/src/test/rustdoc/include_str_cut.rs b/src/test/rustdoc/include_str_cut.rs new file mode 100644 index 0000000000000..cbc1ba8db7529 --- /dev/null +++ b/src/test/rustdoc/include_str_cut.rs @@ -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() {} diff --git a/src/test/rustdoc/short-line.md b/src/test/rustdoc/short-line.md new file mode 100644 index 0000000000000..eff713baac4a8 --- /dev/null +++ b/src/test/rustdoc/short-line.md @@ -0,0 +1,2 @@ +inc2 +x