Skip to content

doc_auto_cfg obfuscates documentation formatting #129889

Open
@imrn99

Description

@imrn99

Problem

I generated documentation for my project, first using stable and then nightly (to document features). The doc generated by the nightly toolchain is formatted very strangely. After removing / adding the doc_auto_cfg nightly feature, it seems that the feature is the cause of this:

Stable & Beta Nightly (with doc_auto_cfg) Nightly (no doc_auto_cfg)
stable-and-beta nightly nightly-no-feat

While I would expect feature-dependent items to have their formatting altered, it seems that every item is affected here.

Steps

  1. Document an item that is both
    • accessible through public modules
    • re-exported publicly (e.g. in a prelude)
  2. generate the doc using cargo +nightly doc, see result
  3. enable the doc_auto_cfg feature, repeat step 2

Possible Solution(s)

FWIW I'm guessing there is some hard-coded html/css somewhere to handle the small feature note; maybe the position of the note puts a constraint on text width?

Notes

I'm guessing the issue occurs whenever there is a public re-exports of an tiem that "has a public path".

I have a custom build script to conditionally enable some gated features depending on the toolchain used to build:

// build.rs

#[rustversion::nightly]
fn set_rustc_channel_cfg() -> &'static str {
    "nightly"
}

#[rustversion::beta]
fn set_rustc_channel_cfg() -> &'static str {
    "beta"
}

#[rustversion::stable]
fn set_rustc_channel_cfg() -> &'static str {
    "stable"
}

fn main() {
    println!("cargo:rustc-cfg={}", set_rustc_channel_cfg());
}
// lib.rs

// ...

#![allow(unexpected_cfgs)]
#![cfg_attr(nightly, feature(doc_auto_cfg))]

// ...

Version

Nightly

cargo 1.83.0-nightly (8f40fc59f 2024-08-21)
release: 1.83.0-nightly
commit-hash: 8f40fc59fb0c8df91c97405785197f3c630304ea
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: AlmaLinux 9.4.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions