你如何处理“无法解析代码块作为Rust代码”rustdoc警告?

问题描述 投票:0回答:1

我正在编写一些生锈的doc示例(正在编译):

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

cargo doc给了我这个[错误的]警告:

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
    |        ^^^^^^^

我应该只是压制这个警告..还是这里有什么东西?

rust rustdoc
1个回答
2
投票

您可以通过在代码块中使用有效的Rust代码来修复错误。


这再现了问题:

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

不要在代码块之前添加虚假空格。在Markdown中,四个空格计为代码的开头,因此您实际上已经完成了HTML的等效操作:

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

正如它告诉你的那样,```不是有效的Rust代码。

© www.soinside.com 2019 - 2024. All rights reserved.