diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 8584e0aff0538..4d6e04dc3453a 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -2884,6 +2884,13 @@ class DocSearch {
return a - b;
}
+ // sort re-exports lower
+ a = Number(aai.ty === itemTypes.import);
+ b = Number(bbi.ty === itemTypes.import);
+ if (a !== b) {
+ return a - b;
+ }
+
// sort deprecated items later
a = Number(aai.deprecated);
b = Number(bbi.deprecated);
diff --git a/tests/rustdoc-js-std/println-typo.js b/tests/rustdoc-js-std/println-typo.js
index b91e7883b995f..fe00dcc75a861 100644
--- a/tests/rustdoc-js-std/println-typo.js
+++ b/tests/rustdoc-js-std/println-typo.js
@@ -8,8 +8,8 @@ const EXPECTED = {
{ 'path': 'std', 'name': 'println' },
{ 'path': 'std::prelude::v1', 'name': 'println' },
{ 'path': 'std', 'name': 'print' },
- { 'path': 'std::prelude::v1', 'name': 'print' },
{ 'path': 'std', 'name': 'eprintln' },
+ { 'path': 'std::prelude::v1', 'name': 'print' },
{ 'path': 'std::prelude::v1', 'name': 'eprintln' },
],
};
diff --git a/tests/rustdoc-js/auxiliary/zzzzz.rs b/tests/rustdoc-js/auxiliary/zzzzz.rs
new file mode 100644
index 0000000000000..19c9d1c247af9
--- /dev/null
+++ b/tests/rustdoc-js/auxiliary/zzzzz.rs
@@ -0,0 +1,4 @@
+//@ edition:2021
+
+#![crate_name = "zzzzz"]
+pub struct Eepy;
diff --git a/tests/rustdoc-js/import-crate-preference.js b/tests/rustdoc-js/import-crate-preference.js
new file mode 100644
index 0000000000000..2a22cffb128f7
--- /dev/null
+++ b/tests/rustdoc-js/import-crate-preference.js
@@ -0,0 +1,23 @@
+// This test ensures that imports have lower ranking than other matches,
+// even if those matches have shorter names.
+
+const EXPECTED = [
+ {
+ 'query': 'Eepy',
+ 'others': [
+ { 'path': 'zzzzz', 'name': 'Eepy' },
+ ],
+ },
+ {
+ 'query': 'zzzzz::Eepy',
+ 'others': [
+ { 'path': 'zzzzz', 'name': 'Eepy' },
+ ],
+ },
+ {
+ 'query': 'foo::Eepy',
+ 'others': [
+ { 'path': 'foo', 'name': 'Eepy' },
+ ],
+ },
+];
diff --git a/tests/rustdoc-js/import-crate-preference.rs b/tests/rustdoc-js/import-crate-preference.rs
new file mode 100644
index 0000000000000..a3e3f7419da88
--- /dev/null
+++ b/tests/rustdoc-js/import-crate-preference.rs
@@ -0,0 +1,9 @@
+//@ aux-crate:zzzzz=zzzzz.rs
+//@ aux-build:zzzzz.rs
+//@ build-aux-docs
+//@ edition:2021
+
+#![crate_name = "foo"]
+
+#[doc(no_inline)]
+pub use zzzzz::Eepy;
diff --git a/tests/rustdoc-js/reexport-dedup.js b/tests/rustdoc-js/reexport-dedup.js
index 979619c50cd8c..e339cd99ac954 100644
--- a/tests/rustdoc-js/reexport-dedup.js
+++ b/tests/rustdoc-js/reexport-dedup.js
@@ -4,7 +4,7 @@ const EXPECTED = [
{
'query': 'Subscriber',
'others': [
- { 'path': 'foo', 'name': 'Subscriber' },
+ { 'path': 'foo::fmt', 'name': 'Subscriber' },
],
},
{