rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.53k stars 12.74k forks source link

`doc_auto_cfg` obfuscates documentation formatting #129889

Open imrn99 opened 2 months ago

imrn99 commented 2 months ago

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]
weihanglo commented 2 months ago

This seems more like a rustdoc issue than Cargo. I'll transfer it to rust-lang/rust.

imrn99 commented 2 months ago

This seems more like a rustdoc issue than Cargo. I'll transfer it to rust-lang/rust.

You're right, I jumped the gun a bit because of my build script. Thanks!