diff options
| author | bors <bors@rust-lang.org> | 2024-01-02 10:30:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-02 10:30:58 +0000 |
| commit | ee0d99d98e6368e6a0ddcf6cf17df24967c7b707 (patch) | |
| tree | ade6b27ef29c1163352a46180e5dc1a09a7a6456 | |
| parent | 60fe5fd98db422c6ed2337ceba205611e9c48f88 (diff) | |
| parent | 99b30ba22fa3377d61d5f9f3a33ae80454b4efac (diff) | |
| download | rust-ee0d99d98e6368e6a0ddcf6cf17df24967c7b707.tar.gz rust-ee0d99d98e6368e6a0ddcf6cf17df24967c7b707.zip | |
Auto merge of #16081 - riverbl:trailing-whitespace, r=Veykril
Don't trim trailing whitespace from doc comments Don't trim trailing whitespace from doc comments as multiple trailing spaces indicates a hard line break in Markdown. I'd have liked to add a unit test for `docs_from_attrs`, but couldn't find a reasonable way to get an `&Attrs` object for use in the test. Fixes #15877.
| -rw-r--r-- | crates/ide-db/src/documentation.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index 26f3cd28a27..cc8e8431708 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -138,15 +138,13 @@ pub fn docs_from_attrs(attrs: &hir::Attrs) -> Option<String> { for doc in docs { // str::lines doesn't yield anything for the empty string if !doc.is_empty() { - buf.extend(Itertools::intersperse( - doc.lines().map(|line| { - line.char_indices() - .nth(indent) - .map_or(line, |(offset, _)| &line[offset..]) - .trim_end() - }), - "\n", - )); + // We don't trim trailing whitespace from doc comments as multiple trailing spaces + // indicates a hard line break in Markdown. + let lines = doc.lines().map(|line| { + line.char_indices().nth(indent).map_or(line, |(offset, _)| &line[offset..]) + }); + + buf.extend(Itertools::intersperse(lines, "\n")); } buf.push('\n'); } |
