Skip to content

Commit ccbaf8b

Browse files
committed
De-emphasize unstable items in rustdoc item table
1 parent 5facb42 commit ccbaf8b

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/librustdoc/html/render/print_item.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ macro_rules! item_template_methods {
147147
const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">";
148148
const ITEM_TABLE_CLOSE: &str = "</ul>";
149149
const ITEM_TABLE_ROW_OPEN: &str = "<li>";
150+
const ITEM_TABLE_ROW_OPEN_UNSTABLE: &str = "<li class=\"unstable\">";
150151
const ITEM_TABLE_ROW_CLOSE: &str = "</li>";
151152

152153
// A component in a `use` path, like `string` in std::string::ToString
@@ -527,7 +528,12 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
527528
_ => "",
528529
};
529530

530-
w.write_str(ITEM_TABLE_ROW_OPEN);
531+
w.write_str(if is_unstable(myitem, tcx) {
532+
ITEM_TABLE_ROW_OPEN_UNSTABLE
533+
} else {
534+
ITEM_TABLE_ROW_OPEN
535+
});
536+
531537
let docs =
532538
MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)).into_string();
533539
let (docs_before, docs_after) = if docs.is_empty() {
@@ -594,13 +600,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
594600
write!(f, "{}", tag_html("deprecated", "", message))?;
595601
}
596602

597-
// The "rustc_private" crates are permanently unstable so it makes no sense
598-
// to render "unstable" everywhere.
599-
if item
600-
.stability(tcx)
601-
.as_ref()
602-
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
603-
{
603+
if is_unstable(item, tcx) {
604604
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
605605
}
606606

@@ -627,6 +627,12 @@ fn extra_info_tags<'a, 'tcx: 'a>(
627627
})
628628
}
629629

630+
fn is_unstable<'a, 'tcx: 'a>(item: &'a clean::Item, tcx: TyCtxt<'tcx>) -> bool {
631+
// The "rustc_private" crates are permanently unstable so it makes no sense
632+
// to render "unstable" everywhere.
633+
item.stability(tcx).as_ref().is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
634+
}
635+
630636
fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
631637
let tcx = cx.tcx();
632638
let header = it.fn_header(tcx).expect("printing a function which isn't a function");

src/librustdoc/html/static/css/rustdoc.css

+3
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,9 @@ table,
819819
.item-table > li > .item-name {
820820
padding-right: 1.25rem;
821821
}
822+
.item-table > li.unstable > .item-name > a {
823+
opacity: 0.70;
824+
}
822825

823826
.search-results-title {
824827
margin-top: 0;

tests/rustdoc/stability.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
pub struct AaStable;
1212

1313
pub struct Unstable {
14+
// @has stability/index.html '//ul[@class="item-table"]/li[@class="unstable"]//a' Unstable
1415
// @has stability/struct.Unstable.html \
1516
// '//span[@class="item-info"]//div[@class="stab unstable"]' \
1617
// 'This is a nightly-only experimental API'

0 commit comments

Comments
 (0)