Description
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 ) |
---|---|---|
![]() |
![]() |
![]() |
While I would expect feature-dependent items to have their formatting altered, it seems that every item is affected here.
Steps
- Document an item that is both
- accessible through public modules
- re-exported publicly (e.g. in a prelude)
- generate the doc using
cargo +nightly doc
, see result - 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]