Skip to content
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

regression: rustdoc interprets the * in /** */ doc comments as literal Markdown #92872

Closed
dalcde opened this issue Jan 13, 2022 · 9 comments · Fixed by #93038
Closed

regression: rustdoc interprets the * in /** */ doc comments as literal Markdown #92872

dalcde opened this issue Jan 13, 2022 · 9 comments · Fixed by #93038
Assignees
Labels
A-markdown-parsing Area: Markdown parsing for doc-comments C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Milestone

Comments

@dalcde
Copy link
Contributor

dalcde commented Jan 13, 2022

Code

I tried this code:

/**
 *     a
 */
pub fn foo() {}

When I run cargo test, I get

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 1 test
test src/lib.rs - foo (line 1) ... FAILED

failures:

---- src/lib.rs - foo (line 1) stdout ----
error[E0425]: cannot find value `a` in this scope
 --> src/lib.rs:2:1
  |
3 | a
  | ^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
Couldn't compile the test.

failures:
    src/lib.rs - foo (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.41s

Oddly it doesn't fail with /** replaced by ///.

This worked on rust version 1.60.0-nightly (092e1c9d2 2022-01-09) but failed on rust version 1.60.0-nightly (1409c015b 2022-01-11)

@dalcde dalcde added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jan 13, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 13, 2022
@Alexendoo
Copy link
Member

bisects to 89b9f7b, likely #92357

@Alexendoo Alexendoo added A-doctests Area: Documentation tests, run by rustdoc regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed regression-untriaged Untriaged performance or correctness regression. labels Jan 13, 2022
@camelid camelid added this to the 1.60.0 milestone Jan 14, 2022
@camelid
Copy link
Member

camelid commented Jan 14, 2022

cc @GuillaumeGomez

@camelid
Copy link
Member

camelid commented Jan 14, 2022

The docs for the MCVE render with an itemized bullet at the top of the page on nightly, but not on stable. I think this is why replacing the /** with /// makes the error go away: the * is interpreted as part of the docs, so it triggers the indented text to be treated as a code block (it seems there must be preceding text to trigger the code block formatting).

image

@camelid
Copy link
Member

camelid commented Jan 14, 2022

It seems like /** */ comments are completely broken:

/**
 * Hello!
 */
pub fn foo() {}

image

I still don't understand how that change could've cause this though; the particular code removed was related to trimming whitespace, not asterisks. Must be a strange cross-interaction.

@camelid camelid changed the title Nightly rust mistakes comment for doctest regression: rustdoc interprets the * in /** */ doc comments as literal Markdown Jan 14, 2022
@camelid camelid added A-markdown-parsing Area: Markdown parsing for doc-comments and removed A-doctests Area: Documentation tests, run by rustdoc labels Jan 14, 2022
@GuillaumeGomez
Copy link
Member

The /** */ comments have always been working like this. It's not supposed to contain * at the beginning of each line.

@camelid
Copy link
Member

camelid commented Jan 14, 2022

@GuillaumeGomez They actually haven't always been like this; this is a regression. On stable, it looks like this:

image

@GuillaumeGomez
Copy link
Member

Interesting. How did we make the difference between:

/**
hello

 * list
 * list

and:

/**
* hello
*  * list
*  * list
*/

?

Do we need to have a star at each line or something?

@camelid
Copy link
Member

camelid commented Jan 14, 2022

I'm not sure exactly how it works, but I believe it's handled by this code (the code modified by the regressing PR, though I'm not sure how it caused the regression): https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/util/comments/fn.beautify_doc_string.html

@GuillaumeGomez
Copy link
Member

It's because we stopped trimming the beginning and the end of the doc comments to prevent bugs when different doc comment kinds are merged. I'm fixing it.

@GuillaumeGomez GuillaumeGomez self-assigned this Jan 18, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 20, 2022
…r=notriddle

Fix star handling in block doc comments

Fixes rust-lang#92872.

Some extra explanation about this PR and why rust-lang#92357 created this regression: when we merge doc comment kinds for example in:

```rust
/// he
/**
* hello
*/
#[doc = "boom"]
```

We don't want to remove the empty lines between them. However, to correctly compute the "horizontal trim", we still need it, so instead, I put back a part of the "vertical trim" directly in the "horizontal trim" computation so it doesn't impact the output buffer but allows us to correctly handle the stars.

r? ``@camelid``
@bors bors closed this as completed in 6c627d2 Jan 20, 2022
@rustbot rustbot removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-markdown-parsing Area: Markdown parsing for doc-comments C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants