diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 054cfe7597ea5..b487cfa5c2553 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -213,7 +213,7 @@ a.anchor,
h1 a,
.search-results a,
.stab,
-.result-name .primitive > i, .result-name .keyword > i {
+.result-name i {
color: var(--main-color);
}
@@ -887,7 +887,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
.search-results .result-name span.alias {
color: var(--search-results-alias-color);
}
-.search-results .result-name span.grey {
+.search-results .result-name .grey {
color: var(--search-results-grey-color);
}
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 62afe40bb3155..eff8aa79caf9c 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -35,6 +35,35 @@ const itemTypes = [
"traitalias",
];
+const longItemTypes = [
+ "module",
+ "extern crate",
+ "re-export",
+ "struct",
+ "enum",
+ "function",
+ "type alias",
+ "static",
+ "trait",
+ "",
+ "trait method",
+ "method",
+ "struct field",
+ "enum variant",
+ "macro",
+ "primitive type",
+ "associated type",
+ "constant",
+ "associated constant",
+ "union",
+ "foreign type",
+ "keyword",
+ "existential type",
+ "attribute macro",
+ "derive macro",
+ "trait alias",
+];
+
// used for special search precedence
const TY_PRIMITIVE = itemTypes.indexOf("primitive");
const TY_KEYWORD = itemTypes.indexOf("keyword");
@@ -1836,16 +1865,11 @@ function initSearch(rawSearchIndex) {
array.forEach(item => {
const name = item.name;
const type = itemTypes[item.ty];
+ const longType = longItemTypes[item.ty];
+ const typeName = longType.length !== 0 ? `${longType}` : "?";
length += 1;
- let extra = "";
- if (type === "primitive") {
- extra = " (primitive type)";
- } else if (type === "keyword") {
- extra = " (keyword)";
- }
-
const link = document.createElement("a");
link.className = "result-" + type;
link.href = item.href;
@@ -1863,13 +1887,14 @@ function initSearch(rawSearchIndex) {
alias.insertAdjacentHTML(
"beforeend",
- " - see ");
+ " - see ");
resultName.appendChild(alias);
}
+
resultName.insertAdjacentHTML(
"beforeend",
- item.displayPath + "" + name + extra + "");
+ `${typeName} ${item.displayPath}${name}`);
link.appendChild(resultName);
const description = document.createElement("div");
diff --git a/tests/rustdoc-gui/search-reexport.goml b/tests/rustdoc-gui/search-reexport.goml
index fd817b58990c5..0ce4e99339fb1 100644
--- a/tests/rustdoc-gui/search-reexport.goml
+++ b/tests/rustdoc-gui/search-reexport.goml
@@ -14,7 +14,7 @@ assert-attribute: (
"//a[@class='result-import']",
{"href": "../test_docs/index.html#reexport.TheStdReexport"},
)
-assert-text: ("//a[@class='result-import']", "test_docs::TheStdReexport")
+assert-text: ("a.result-import .result-name", "re-export test_docs::TheStdReexport")
click: "//a[@class='result-import']"
// We check that it has the background modified thanks to the focus.
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"})
@@ -25,8 +25,8 @@ press-key: 'Enter'
write: (".search-input", "AliasForTheStdReexport")
wait-for: "//a[@class='result-import']"
assert-text: (
- "//a[@class='result-import']",
- "AliasForTheStdReexport - see test_docs::TheStdReexport",
+ "a.result-import .result-name",
+ "AliasForTheStdReexport - see re-export test_docs::TheStdReexport",
)
// Same thing again, we click on it to ensure the background is once again set as expected.
click: "//a[@class='result-import']"
diff --git a/tests/rustdoc-gui/search-result-color.goml b/tests/rustdoc-gui/search-result-color.goml
index 90f7160b72490..c75e4141434e4 100644
--- a/tests/rustdoc-gui/search-result-color.goml
+++ b/tests/rustdoc-gui/search-result-color.goml
@@ -65,12 +65,6 @@ assert-css: (
{"border-bottom-color": "#aaa3"}
)
-// Checking the color of "keyword" text.
-assert-css: (
- "//*[@class='result-name']//*[text()='(keyword)']",
- {"color": "#788797"},
-)
-
store-value: (entry_color, "#0096cf") // color of the search entry
store-value: (hover_entry_color, "#fff") // color of the hovered/focused search entry
store-value: (background_color, "transparent") // background color
@@ -182,12 +176,6 @@ assert-css: (
{"border-bottom-color": "#aaa3"}
)
-// Checking the color for "keyword" text.
-assert-css: (
- "//*[@class='result-name']//*[text()='(keyword)']",
- {"color": "#ddd"},
-)
-
store-value: (entry_color, "#ddd") // color of the search entry
store-value: (hover_entry_color, "#ddd") // color of the hovered/focused search entry
store-value: (background_color, "transparent") // background color
@@ -284,12 +272,6 @@ assert-css: (
{"border-bottom-color": "#aaa3"}
)
-// Checking the color for "keyword" text.
-assert-css: (
- "//*[@class='result-name']//*[text()='(keyword)']",
- {"color": "#000"},
-)
-
store-value: (entry_color, "#000") // color of the search entry
store-value: (hover_entry_color, "#000") // color of the hovered/focused search entry
store-value: (background_color, "transparent") // background color
diff --git a/tests/rustdoc-gui/search-result-display.goml b/tests/rustdoc-gui/search-result-display.goml
index bf096f62c4838..afb3a44be303f 100644
--- a/tests/rustdoc-gui/search-result-display.goml
+++ b/tests/rustdoc-gui/search-result-display.goml
@@ -7,11 +7,11 @@ press-key: 'Enter'
wait-for: "#crate-search"
// The width is returned by "getComputedStyle" which returns the exact number instead of the
// CSS rule which is "50%"...
-assert-css: (".search-results div.desc", {"width": "310px"})
+assert-size: (".search-results div.desc", {"width": 310})
set-window-size: (600, 100)
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
// when computed it's larger.
-assert-css: (".search-results div.desc", {"width": "566px"})
+assert-size: (".search-results div.desc", {"width": 566})
// The result set is all on one line.
assert-css: (".search-results .result-name > span", {"display": "inline"})
diff --git a/tests/rustdoc-gui/search-result-keyword.goml b/tests/rustdoc-gui/search-result-keyword.goml
index 5d56e9d9cd42d..1b2be6d4e3e22 100644
--- a/tests/rustdoc-gui/search-result-keyword.goml
+++ b/tests/rustdoc-gui/search-result-keyword.goml
@@ -5,9 +5,4 @@ write: (".search-input", "CookieMonster")
press-key: 'Enter'
// Waiting for the search results to appear...
wait-for: "#search-tabs"
-// Note: The two next assert commands could be merged as one but readability would be
-// less good.
-//
-// Checking that the CSS is displaying " (keyword)" in italic.
-assert-text: (".result-name span.keyword > i", "(keyword)")
-assert-text: (".result-name span.keyword", "CookieMonster (keyword)")
+assert-text: (".result-keyword .result-name", "keyword CookieMonster")