diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 6c34d31cc918..15f460eba1af 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -359,7 +359,8 @@ summary.hideme,
.rustdoc-breadcrumbs,
.search-switcher,
/* This selector is for the items listed in the "all items" page. */
-ul.all-items {
+ul.all-items,
+.deprecated-count {
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
}
@@ -2671,6 +2672,18 @@ However, it's not needed with smaller screen width because the doc/code block is
display: none;
}
+.deprecated-count {
+ display: none;
+}
+/*
+The `:not(:empty)` is a little trick to not have to add conditions in JS to hide/show the marker.
+It's entirely based on whether it has content and if the setting is enabled.
+*/
+.hide-deprecated-items .deprecated-count:not(:empty) {
+ display: block;
+ margin: 10px 0;
+}
+
/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 9961c1447ec2..55ff48846dcb 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -158,6 +158,7 @@ const REGEX_INVALID_TYPE_FILTER = /[^a-z]/ui;
const MAX_RESULTS = 200;
const NO_TYPE_FILTER = -1;
+const DEPRECATED_COUNT_SELECTOR = "deprecated-count";
/**
* The [edit distance] is a metric for measuring the difference between two strings.
@@ -4904,7 +4905,12 @@ async function addTab(results, query, display, finishedCallback, isTypeSearch) {
let output = document.createElement("ul");
output.className = "search-results " + extraClass;
+ const deprecatedCountElem = document.createElement("span");
+ deprecatedCountElem.className = DEPRECATED_COUNT_SELECTOR;
+ output.appendChild(deprecatedCountElem);
+
let count = 0;
+ let deprecatedCount = 0;
/** @type {Promise[]} */
const descList = [];
@@ -4922,6 +4928,10 @@ async function addTab(results, query, display, finishedCallback, isTypeSearch) {
link.className = "result-" + type;
if (obj.item.deprecated) {
link.className += " deprecated";
+ deprecatedCount += 1;
+ const plural = deprecatedCount > 1 ? "s" : "";
+ deprecatedCountElem.innerText =
+ `${deprecatedCount} deprecated item${plural} hidden by setting`;
}
link.href = obj.href;
@@ -5411,7 +5421,7 @@ function registerSearchEvents() {
const active = document.activeElement;
if (active) {
const previous = active.previousElementSibling;
- if (previous) {
+ if (previous && previous.className !== DEPRECATED_COUNT_SELECTOR) {
// @ts-expect-error
previous.focus();
} else {
diff --git a/tests/rustdoc-gui/setting-hide-deprecated.goml b/tests/rustdoc-gui/setting-hide-deprecated.goml
index 6dc5a6bff175..0fefe00f9457 100644
--- a/tests/rustdoc-gui/setting-hide-deprecated.goml
+++ b/tests/rustdoc-gui/setting-hide-deprecated.goml
@@ -69,7 +69,7 @@ wait-for-css: ("details" + |deprecated_class|, {"display": "block"}, ALL)
// And now we check with the search results.
call-function: ("perform-search", {"query": "deprecated::depr"})
-// There should at least 7 results.
+// There should be at least 7 results.
store-count: ("#results ul.search-results.active > a", nb_search_results)
assert: |nb_search_results| >= 7
// There should be at least 5 deprecated items.
@@ -77,6 +77,12 @@ store-count: ("#results ul.search-results.active > a" + |deprecated_class|, nb_d
assert: |nb_search_results| >= 5
// Deprecated items should all be displayed.
assert-css: ("#results ul.search-results.active > a" + |deprecated_class|, {"display": "grid"}, ALL)
+// The "X deprecated items hidden by setting" element should not be displayed.
+assert-text: (
+ "#results ul.search-results.active .deprecated-count",
+ "5 deprecated items hidden by setting",
+)
+assert-css: ("#results ul.search-results.active .deprecated-count", {"display": "none"})
// We enable the "hide deprecated items" setting.
call-function: ("open-settings-menu", {})
click: "#hide-deprecated-items"
@@ -86,11 +92,16 @@ wait-for-css: (
{"display": "none"},
ALL,
)
+// The "X deprecated items hidden by setting" element should be displayed.
+assert-css: ("#results ul.search-results.active .deprecated-count", {"display": "block"})
// Finally we check that the future deprecated item doesn't have the deprecated class in the search
-// and therefore isn't impact by the setting.
-call-function: ("perform-search", {"query": "deprecated::future_deprecated"})
+// and therefore isn't impacted by the setting.
+call-function: ("perform-search", {"query": '"future_deprecated_fn"'})
assert-text: (
"#results ul.search-results.active > a:not(" + |deprecated_class| + ") .path",
" lib2::deprecated::NonDeprecatedStruct::future_deprecated_fn",
)
+// The "X deprecated items hidden by setting" element should now be empty, and therefore not displayed.
+assert-text: ("#results ul.search-results.active .deprecated-count", "")
+assert-css: ("#results ul.search-results.active .deprecated-count", {"display": "none"})