diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 4e3b532ae08ae..be0ec425946c2 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -1393,6 +1393,7 @@ function initSearch(rawSearchIndex) {
*/
async function sortResults(results, isType, preferredCrate) {
const userQuery = parsedQuery.userQuery;
+ const casedUserQuery = parsedQuery.original;
const result_list = [];
for (const result of results.values()) {
result.item = searchIndex[result.id];
@@ -1403,6 +1404,13 @@ function initSearch(rawSearchIndex) {
result_list.sort((aaa, bbb) => {
let a, b;
+ // sort by exact case-sensitive match
+ a = (aaa.item.name !== casedUserQuery);
+ b = (bbb.item.name !== casedUserQuery);
+ if (a !== b) {
+ return a - b;
+ }
+
// sort by exact match with regard to the last word (mismatch goes later)
a = (aaa.word !== userQuery);
b = (bbb.word !== userQuery);
diff --git a/tests/rustdoc-js-std/exact-case.js b/tests/rustdoc-js-std/exact-case.js
new file mode 100644
index 0000000000000..d9faff22fff70
--- /dev/null
+++ b/tests/rustdoc-js-std/exact-case.js
@@ -0,0 +1,7 @@
+const EXPECTED = {
+ 'query': 'Copy',
+ 'others': [
+ { 'path': 'std::marker', 'name': 'Copy' },
+ { 'path': 'std::fs', 'name': 'copy' },
+ ],
+}