How do you handle the “could not parse code block as Rust code” rustdoc warning?

折月煮酒 提交于 2019-12-20 06:19:07

问题


I'm writing some rust doc examples (that are compiling):

/// ```rust
/// # #[macro_use]
/// # extern crate ...
/// ...
/// ```

But cargo doc gives me this [incorrect] warning:

warning: could not parse code block as Rust code
   --> srml/support/src/dispatch.rs:105:5
    |
105 |   ///    ```rust
    |  ________^
106 | | /// # #[macro_use]
    | |_
    |
    = note: error from rustc: unknown start of token: `
help: mark blocks that do not contain Rust code as text
    |
105 | ///    ```textrust
    |        ^^^^^^^

Should I just suppress this warning.. or is something off here?


回答1:


You fix the error by using valid Rust code inside the code block.


This reproduces the problem:

///    ```rust
///
///    ```
pub fn foo() {}

Don't add spurious whitespace before your code blocks. In Markdown, four spaces counts as the beginning of code, so you have actually done the equivalent of the HTML:

<code>```rust  ```</code>

As it tells you, ``` isn't valid Rust code.



来源:https://stackoverflow.com/questions/55731174/how-do-you-handle-the-could-not-parse-code-block-as-rust-code-rustdoc-warning

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!