Skip to content

Commit bfcdb74

Browse files
committed
De-emphasize unstable items in rustdoc item table
1 parent e68f935 commit bfcdb74

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/librustdoc/html/render/print_item.rs

+15-6
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,11 +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.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
600-
== Some(true)
601-
{
603+
if is_unstable(item, tcx) {
602604
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
603605
}
604606

@@ -625,6 +627,13 @@ fn extra_info_tags<'a, 'tcx: 'a>(
625627
})
626628
}
627629

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().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
634+
== Some(true)
635+
}
636+
628637
fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
629638
let tcx = cx.tcx();
630639
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

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#![unstable(feature = "test", issue = "none")]
44

5+
// @has stability/index.html '//ul[@class="item-table"]/li[@class="unstable"]//a' Unstable
6+
57
pub struct Unstable {
68
// @has stability/struct.Unstable.html \
79
// '//span[@class="item-info"]//div[@class="stab unstable"]' \

0 commit comments

Comments
 (0)