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

nightly: unexpected "could not parse code block" in indented block docs in presence of backticks #58473

Closed
vthriller opened this issue Feb 15, 2019 · 5 comments
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@vthriller
Copy link

I believe this is a minimal example. Warning disappears if either:

  • backticks are removed
  • indentation is removed
  • ///-style formatting is used
// don't even need to be in `impl`, yeah
//pub struct Foo {}
//impl Foo {
    /**
    Does nothing, returns `()`

    yadda-yadda-yadda
    */
    pub fn foo() {}
//}
$ cargo doc
 Documenting rust-nightly-doc-wat v0.1.0 (/home/thriller/tmp/rust-nightly-doc-wat)
    Finished dev [unoptimized + debuginfo] target(s) in 1.08s
$ cargo +nightly doc
 Documenting rust-nightly-doc-wat v0.1.0 (/home/thriller/tmp/rust-nightly-doc-wat)
warning: could not parse code block as Rust code
 --> src/lib.rs:5:5
  |
5 | /     Does nothing, returns `()`
6 | |
7 | |     yadda-yadda-yadda
  | |_____________________^
  |
  = note: error from rustc: unknown start of token: `

    Finished dev [unoptimized + debuginfo] target(s) in 1.29s
$ rustc +nightly --version --verbose
rustc 1.34.0-nightly (e54494727 2019-02-13)
binary: rustc
commit-hash: e54494727855cd14229f5d456591ed2a2f027c46
commit-date: 2019-02-13
host: x86_64-unknown-linux-gnu
release: 1.34.0-nightly
LLVM version: 8.0

(straight from rustup)

@vthriller
Copy link
Author

Oh, and the HTML render is fine, no unexpected code blocks or anything crazy:

image

@estebank estebank added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 15, 2019
@GuillaumeGomez
Copy link
Member

You should see backticks in rendered docs. However, the issue is on your side. You have to add a backslash before them. :) Try this out and tell us if it's still an issue.

@vthriller
Copy link
Author

vthriller commented Feb 17, 2019

Wait, what? I don't get your reply at all. In case you missed it, I'm not complaining about how docstring is rendered, I only added screenshot to show that not all parts of rustdoc try to see markdown-indented-code-blocks where there are none; the issue is with the warning that makes no sense.

@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented Feb 20, 2019

I get these warnings when compiling the boolinator crate (for example, for this doc comment). Full output:

warning: could not parse code block as Rust code
  --> src/lib.rs:52:5
   |
52 |     If this value is `true`, returns `Some(())`; `None` otherwise.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:57:5
   |
57 |     If this value is `true`, returns `Some(some)`; `None` otherwise.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:62:5
   |
62 |     If this value is `true`, returns `Some(some())`; `None` otherwise. 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:68:5
   |
68 |     If this value is `true`, returns `opt`; `None` otherwise. 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:73:5
   |
73 |     If this value is `true`, returns `opt()`; `None` otherwise. 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:79:5
   |
79 |     If this value is `true`, returns `Ok(ok)`; `Err(err)` otherwise. 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:84:5
   |
84 |     If this value is `true`, returns `Ok(ok())`; `Err(err())` otherwise. 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:90:5
   |
90 |     If this value is `true`, returns `Ok(())`; `Err(err)` otherwise.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
  --> src/lib.rs:95:5
   |
95 |     If this value is `true`, returns `Ok(())`; `Err(err())` otherwise.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: error from rustc: unknown start of token: `

warning: could not parse code block as Rust code
   --> src/lib.rs:101:5
    |
101 |     If this value is `true`, does nothing; panics with `msg` otherwise.
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: error from rustc: unknown start of token: 

I very much doubt that this is intended.

Warning occurs with:

  • rustc 1.33.0-nightly (7bac68a 2019-01-21)
  • rustc 1.34.0-nightly (146aa60 2019-02-18)

No warnings with rustc 1.33.0-nightly (0c0c585 2019-01-19). So the problem is in these commits. Thus, the PR causing these warnings is probably #56884. CC @euclio

@euclio
Copy link
Contributor

euclio commented Feb 20, 2019

Yeah, the pass to check codeblock syntax is probably missing handling for the extra margin introduced by comments in that style. Shouldn't be too hard to fix.

In the meantime, you can work around this by writing your comments with /// or like so:

/**
 * If this value is `true`, returns `Some(())`; `None` otherwise.
 */

Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
…isdreavus

rustdoc: move collapse and unindent docs passes earlier

Moves these passes as early as possible so later passes will see the same markdown that is passed to the test collector.

Fixes rust-lang#58473, and a similar issue with the private-doc-tests lint.

r? @QuietMisdreavus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants