Skip to content

Commit

Permalink
De-emphasize unstable items in rustdoc item table
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 24, 2023
1 parent e68f935 commit bfcdb74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ macro_rules! item_template_methods {
const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">";
const ITEM_TABLE_CLOSE: &str = "</ul>";
const ITEM_TABLE_ROW_OPEN: &str = "<li>";
const ITEM_TABLE_ROW_OPEN_UNSTABLE: &str = "<li class=\"unstable\">";
const ITEM_TABLE_ROW_CLOSE: &str = "</li>";

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

w.write_str(ITEM_TABLE_ROW_OPEN);
w.write_str(if is_unstable(myitem, tcx) {
ITEM_TABLE_ROW_OPEN_UNSTABLE
} else {
ITEM_TABLE_ROW_OPEN
});

let docs =
MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)).into_string();
let (docs_before, docs_after) = if docs.is_empty() {
Expand Down Expand Up @@ -594,11 +600,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
write!(f, "{}", tag_html("deprecated", "", message))?;
}

// The "rustc_private" crates are permanently unstable so it makes no sense
// to render "unstable" everywhere.
if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
== Some(true)
{
if is_unstable(item, tcx) {
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
}

Expand All @@ -625,6 +627,13 @@ fn extra_info_tags<'a, 'tcx: 'a>(
})
}

fn is_unstable<'a, 'tcx: 'a>(item: &'a clean::Item, tcx: TyCtxt<'tcx>) -> bool {
// The "rustc_private" crates are permanently unstable so it makes no sense
// to render "unstable" everywhere.
item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
== Some(true)
}

fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
let tcx = cx.tcx();
let header = it.fn_header(tcx).expect("printing a function which isn't a function");
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,9 @@ table,
.item-table > li > .item-name {
padding-right: 1.25rem;
}
.item-table > li.unstable > .item-name > a {
opacity: 0.70;
}

.search-results-title {
margin-top: 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/rustdoc/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

// @has stability/index.html '//ul[@class="item-table"]/li[@class="unstable"]//a' Unstable

pub struct Unstable {
// @has stability/struct.Unstable.html \
// '//span[@class="item-info"]//div[@class="stab unstable"]' \
Expand Down

0 comments on commit bfcdb74

Please sign in to comment.