Skip to content

Rustdoc warns about comments in code blocks #96233

Open
@macmv

Description

@macmv

Given the following code:

/// ```rust
/// // Hello!
/// ```
fn main() {}

The current output of rustdoc is:

$ rustdoc src/main.rs --document-private-items
warning: Rust code block is empty
 --> src/main.rs:1:5
  |
1 |   /// ```rust
  |  _____^
2 | | /// // Hello!
3 | | /// ```
  | |_______^
  |
  = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default

warning: `rustdoc-sample` (bin "rustdoc-sample" doc) generated 1 warning

Ideally, the output should not give any warnings.

While a standalone comment in a code block is not a common situation, the resulting webpage will highlight it as a comment. I have a code generator, which creates rust code for build scripts. There is a function to generate a comment, and part of the documentation is the resulting comment. Using ```text would solve the warning, but it would not be highlighted as a comment in the resulting webpage. As far as I can tell, this doesn't seem like an empty code block, and I don't think this lint should trigger over it.

Using stable and switching editions doesn't change the output.

Here is a link to a sample repository: https://github.com/macmv/rustdoc-empty-code-block-sample

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions