Skip to content

rustdoc: Failed to parse rust code block with ## in 2024 #136899

Closed
@ehuss

Description

@ehuss

In 2024, rustdoc seems to fail to parse a rust code line that starts with ##.

//! Test
//!
//! ```
//! ##[allow(dead_code)]
//! println!("hello world");
//! ```

In 2021, this renders in a weird way where it strips the first #, but doesn't actually hide the line. I would expect the line to be hidden. I don't know if that is intentional.

Image

In 2024, cargo doc generates a warning:

arning: could not parse code block as Rust code
 --> src/lib.rs:3:5
  |
3 |   //! ```
  |  _____^
4 | | //! ##[allow(dead_code)]
5 | | //! println!("hello world");
6 | | //! ```
  | |_______^
  |
  = note: error from rustc: reserved multi-hash token is forbidden
  = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
help: mark blocks that do not contain Rust code as text
  |
3 | //! ```text
  |        ++++

I'm not sure what I expect here. I assume it is conflicting with the reserved syntax of 2024.

Is the ## form really intended to be supported as a way to hide a line? cc @GuillaumeGomez

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (92bedea1c 2025-02-11)
binary: rustc
commit-hash: 92bedea1c51e3a969d60972be854506ffd8c5cb6
commit-date: 2025-02-11
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 editionC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions