Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ehuss opened this issue Feb 12, 2025 · 3 comments · Fixed by #136927
Closed

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

ehuss opened this issue Feb 12, 2025 · 3 comments · Fixed by #136927
Labels
A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 12, 2025

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
@ehuss ehuss added A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 12, 2025
@fmease
Copy link
Member

fmease commented Feb 12, 2025

So, an "isolated" # hides a line. This specifically excludes the sequence #[ for example which would likely start an attribute.

The sequence ## generally escapes # meaning it gets substituted with #. That's why ##[…] results in #[…]. I don't know why it's treated verbatim in R2024 tho, I haven't checked the source code.

@GuillaumeGomez
Copy link
Member

Checking what's wrong.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 12, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
@GuillaumeGomez
Copy link
Member

I opened #136927 to fix it.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 12, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Feb 13, 2025
…-escape, r=notriddle

Correctly escape hashtags when running `invalid_rust_codeblocks` lint

Fixes rust-lang#136899.

We forgot to use `map_line` when we wrote this lint.

r? `@notriddle`
@bors bors closed this as completed in 9fe0d25 Feb 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2025
Rollup merge of rust-lang#136927 - GuillaumeGomez:add-missing-hashtag-escape, r=notriddle

Correctly escape hashtags when running `invalid_rust_codeblocks` lint

Fixes rust-lang#136899.

We forgot to use `map_line` when we wrote this lint.

r? ``@notriddle``
ehuss added a commit to ehuss/rust that referenced this issue Feb 13, 2025
A small workaround for rust-lang#136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
ehuss added a commit to ehuss/rust that referenced this issue Feb 13, 2025
A small workaround for rust-lang#136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
ehuss added a commit to ehuss/rust that referenced this issue Feb 13, 2025
A small workaround for rust-lang#136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
Shourya742 pushed a commit to Shourya742/rust that referenced this issue Feb 15, 2025
A small workaround for rust-lang#136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants