Skip to content

Trailing whitespace trimmed from doc comments #15877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MinusGix opened this issue Nov 12, 2023 · 2 comments · Fixed by #16081
Closed

Trailing whitespace trimmed from doc comments #15877

MinusGix opened this issue Nov 12, 2023 · 2 comments · Fixed by #16081
Labels
C-bug Category: bug

Comments

@MinusGix
Copy link

rust-analyzer version: 0.4.1728-standalone

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

Example:

/// This is a testing comment to test rustdoc markdown.  
/// This is the next line.
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

In rustdoc, this appears like:
image

However, in VSCode/Lapce, it appears as:
image

The contents of what VSCode receives:

    "contents": {
        "kind": "markdown",
        "value": "\n```rust\ntesting1\n```\n\n```rust\npub fn add(left: usize, right: usize) -> usize\n```\n\n---\n\nThis is a testing comment to test rustdoc markdown.\nThis is the next line."
    },

So it appears that it strips the whitespace at the end of the lines, and then sends it along. Since the receiver is parsing this as markdown, they do the typical behavior of single newlines not being actual linebreaks.

I believe this didn't used to happen until some months back, but I haven't checked which version I remember it being fine on.

It seems to have happened before in #1997 and then been fixed.

@MinusGix MinusGix added the C-bug Category: bug label Nov 12, 2023
@MinusGix MinusGix changed the title Markdown trims whitespace at end of lines Trailing whitespace trimmed from doc comments Nov 12, 2023
@riverbl
Copy link
Contributor

riverbl commented Dec 10, 2023

Trailing whitespace having semantic meaning seems really horrible to me.

rustfmt is clearly aware of trailing spaces having meaning in Markdown, as it will trim a single trailing space from doc comments, but won't trim multiple trailing spaces.

As far as I can tell, either any number of trailing spaces greater than one or a trailing backslash indicates a line break, with no difference in meaning. rustfmt allows either of these forms, and does not normalise the number of trailing spaces.

@bors bors closed this as completed in ee0d99d Jan 2, 2024
@Marcono1234
Copy link

Marcono1234 commented Jan 17, 2024

Trailing whitespace having semantic meaning seems really horrible to me.

As side note: CommonMark (which is used by rustdoc) alternatively supports a trailing \ instead of two spaces to create a hard line break (see specification).
But you should check whether at that location a hard line break is actually needed (and there is no implicit line break, e.g. due to usage of > ... in the next line), otherwise the \ might be shown literally, example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants