From b6f81e04347d9dbd29e59e7dbca3f9289ddb2fe3 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 19 Apr 2023 10:16:14 -0700 Subject: [PATCH] rustdoc-search: give longer notification for type corrections --- src/librustdoc/html/static/js/search.js | 9 +++++++-- tests/rustdoc-gui/search-corrections.goml | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2d0a3f0192b..1bee6987739 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1996,8 +1996,13 @@ function initSearch(rawSearchIndex) { } if (results.query.correction !== null) { - output += "

Showing results for " + - `"${results.query.correction}".

`; + const orig = results.query.returned.length > 0 + ? results.query.returned[0].name + : results.query.elems[0].name; + output += "

" + + `Type "${orig}" not found. ` + + "Showing results for " + + `"${results.query.correction}" instead.

`; } const resultsElem = document.createElement("div"); diff --git a/tests/rustdoc-gui/search-corrections.goml b/tests/rustdoc-gui/search-corrections.goml index 832aa153054..323dd658426 100644 --- a/tests/rustdoc-gui/search-corrections.goml +++ b/tests/rustdoc-gui/search-corrections.goml @@ -22,7 +22,7 @@ assert-css: (".search-corrections", { }) assert-text: ( ".search-corrections", - "Showing results for \"notablestructwithlongname\"." + "Type \"notablestructwithlongnamr\" not found. Showing results for \"notablestructwithlongname\" instead." ) // Corrections do get shown on the "In Return Type" tab. @@ -33,7 +33,7 @@ assert-css: (".search-corrections", { }) assert-text: ( ".search-corrections", - "Showing results for \"notablestructwithlongname\"." + "Type \"notablestructwithlongnamr\" not found. Showing results for \"notablestructwithlongname\" instead." ) // Now, explicit return values @@ -50,5 +50,5 @@ assert-css: (".search-corrections", { }) assert-text: ( ".search-corrections", - "Showing results for \"notablestructwithlongname\"." + "Type \"notablestructwithlongnamr\" not found. Showing results for \"notablestructwithlongname\" instead." )