Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-emphasize unstable items in rustdoc item table #118226

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading