您如何处理“无法将代码块解析为Rust代码"? rustdoc警告? [英] How do you handle the "could not parse code block as Rust code" rustdoc warning?

查看:210
本文介绍了您如何处理“无法将代码块解析为Rust代码"? rustdoc警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些rust doc示例(正在编译):

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

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

但是cargo doc给我这个[错误]警告:

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?

推荐答案

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

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

这重现了问题:

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

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

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>

正如您所知,```不是有效的Rust代码.

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

这篇关于您如何处理“无法将代码块解析为Rust代码"? rustdoc警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆