diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 14387e0d45dfe..f83ca37884dcb 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -147,6 +147,7 @@ macro_rules! item_template_methods { const ITEM_TABLE_OPEN: &str = ""; const ITEM_TABLE_ROW_OPEN: &str = "
  • "; +const ITEM_TABLE_ROW_OPEN_UNSTABLE: &str = "
  • "; const ITEM_TABLE_ROW_CLOSE: &str = "
  • "; // 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: _ => "", }; - 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() { @@ -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"))?; } @@ -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"); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 9efdcd601170e..f29eaaccf5e8e 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -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; diff --git a/tests/rustdoc/stability.rs b/tests/rustdoc/stability.rs index c4d7118d07ff0..226117a1fdb9b 100644 --- a/tests/rustdoc/stability.rs +++ b/tests/rustdoc/stability.rs @@ -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'