Skip to content

cargo doc: pub extern crate causes rest of file to be formatted as code block #150176

@wojciech-graj

Description

@wojciech-graj

Problem

Using pub extern crate to re-export a crate will cause the rest of the file to be formatted as a code block. See the below screenshots.

No re-export

Image

Re-export

Image

Steps

  1. Create a library that depends on any crate, for example:

Cargo.toml

[package]
name = "tmp"
version = "0.1.0"
edition = "2024"

[dependencies]
core2 = "0.4.0"
  1. Re-export the crate using pub extern crate

lib.rs

pub extern crate core2;

/// Doc
pub struct S;
  1. Run cargo doc, and observe the bug

Possible Solution(s)

No response

Notes

I suspect the code block in the generated docs that contains pub extern crate core2; doesn't get closed, causing the rest of the file to also become a code block.

This behavior is currently observable in stable, and was introduced to nightly at some point between 2025-09-14 and 2025-11-27.

Version

cargo 1.92.0 (344c4567c 2025-10-21)
release: 1.92.0
commit-hash: 344c4567c634a25837e3c3476aac08af84cf9203
commit-date: 2025-10-21
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Debian 13.0.0 (trixie) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions