Description
The Problem
If one tries to put feature labels in the main body of the documentation (what goes inside <div class="docblock">
) they get styled differently from the one automatically inserted by rustdoc
running with #![feature(doc_auto_cfg)]
. In particular the layout is bad and can cause the appearance of scrollbars on the right hand side of each involved paragraph.
Here is an example picture:
The desirable look would of course be
Code to generate the example documentation above.
Cargo.toml
:
[package]
name = "doc-example"
version = "0.1.0"
edition = "2021"
[features]
default = ["some-feature"]
some-feature = []
src/lib.rs
:
/*! Cool library.
<!-- REMOVE TO PRODUCE THE BAD VERSION -->
<style>
.docblock .stab {
display: inline-block;
margin-bottom: 0;
padding: 2px;
line-height: 1.2;
border-radius: 3px;
}
</style>
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy this crate even more!
Also, stop using [`bar`] as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using [`bar`] as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using [`bar`] as it's <span class="stab deprecated" title="">deprecated</span>.
Finally, you can use [`quz`] only on <span class="stab portability"><code>Unix or x86-64</code></span>.
Finally, you can use [`quz`] only on <span class="stab portability"><code>Unix or x86-64</code></span>.
Finally, you can use [`quz`] only on <span class="stab portability"><code>Unix or x86-64</code></span>.
*/
#![feature(doc_auto_cfg)]
/// Does fooish things.
#[cfg(feature = "some-feature")]
pub fn foo() {}
/// Does barish things.
#[deprecated(since = "0.1.0", note = "we don't need this anymore")]
pub fn bar() {}
/// Does quzish things.
#[cfg(any(unix, target_arch = "x86_64"))]
pub fn quz() {}
The Cause
The reason is that rustdoc.css
has a special rule for .module-item .stab, .import-item .stab
, whereas it does not address .stab
tags appearing as descendant of .docblock
tags.
The Fix
From a crate developer's point of view, the fix for this is simple enough: just inject the following CSS
.docblock .stab {
display: inline-block;
margin-bottom: 0;
padding: 2px;
line-height: 1.2;
border-radius: 3px;
}
so that they are rendered the same way as the ones generated by rustdoc
's doc_auto_cfg
labels.
The Request
Is there any chance that this CSS gets included in the official rustdoc.css
style?
The fix would probably consist in adding .docblock .stab
to
rust/src/librustdoc/html/static/css/rustdoc.css
Lines 1064 to 1074 in 4f372b1
except that we don't want the left margin, so probably a dedicated rule is more appropriate.