diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-11-08 15:15:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-08 15:15:24 +0100 |
| commit | d9fc7d10414a3b5fb172482911fc39ba2dd6bb37 (patch) | |
| tree | 6f3d2027183fd2b6e6a6a05f792d5bf76179eefa | |
| parent | 931881070a00e869ff52ddfbe243800d256261e8 (diff) | |
| parent | aa6f6f47cd7f83e3898b66e53ff30a414b0a0694 (diff) | |
| download | rust-d9fc7d10414a3b5fb172482911fc39ba2dd6bb37.tar.gz rust-d9fc7d10414a3b5fb172482911fc39ba2dd6bb37.zip | |
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.
| -rw-r--r-- | compiler/rustc_ast/src/util/comments.rs | 2 | ||||
| -rw-r--r-- | src/test/rustdoc/include_str_cut.rs | 7 | ||||
| -rw-r--r-- | src/test/rustdoc/short-line.md | 2 |
3 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_ast/src/util/comments.rs b/compiler/rustc_ast/src/util/comments.rs index 542a330a031..c40aec4b671 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 00000000000..cbc1ba8db75 --- /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 00000000000..eff713baac4 --- /dev/null +++ b/src/test/rustdoc/short-line.md @@ -0,0 +1,2 @@ +inc2 +x |
