From fcbb046ced6d4f93fffa724430a2feb3db0de08a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 24 Jan 2026 00:47:39 +0100 Subject: [PATCH 1/3] Add a marker to tell users that there are hidden (deprecated) items in the search results --- src/librustdoc/html/static/css/rustdoc.css | 11 ++++++++++- src/librustdoc/html/static/js/search.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 486ca9b22539..b62d6b15cf36 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -341,7 +341,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; } @@ -2652,6 +2653,14 @@ However, it's not needed with smaller screen width because the doc/code block is display: none; } +.deprecated-count { + display: none; +} +.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 { From 0e240d32325bdb491f8894b4dc1e720ec756c4f7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 24 Jan 2026 00:48:37 +0100 Subject: [PATCH 2/3] Add GUI regression test for the display and content of the "hidden deprecated item marker" --- tests/rustdoc-gui/setting-hide-deprecated.goml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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"}) From c60ae4dcf255fe6f82525b4b496244bdfeec97d6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 27 Jan 2026 22:41:35 +0100 Subject: [PATCH 3/3] Add code comment explaining how the CSS selector works for deprecated items --- src/librustdoc/html/static/css/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b62d6b15cf36..df92938ec820 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2656,6 +2656,10 @@ However, it's not needed with smaller screen width because the doc/code block is .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;