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 28, 2023
1 parent 5facb42 commit ccbaf8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
22 changes: 14 additions & 8 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,13 +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()
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
{
if is_unstable(item, tcx) {
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
}

Expand All @@ -627,6 +627,12 @@ 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().is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
}

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
1 change: 1 addition & 0 deletions tests/rustdoc/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
pub struct AaStable;

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

0 comments on commit ccbaf8b

Please sign in to comment.