From 731981178d8a9b4a30aae70fb2bd91e0e016bb33 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 30 Oct 2025 16:01:58 +0100 Subject: [PATCH 1/2] [rustdoc search] Include extern crates when filtering on `import` --- src/librustdoc/html/static/js/search.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 0a73d32dac2de..e281139ca38ff 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -3906,6 +3906,8 @@ class DocSearch { return name === "traitalias"; case "macro": return name === "attr" || name === "derive"; + case "import": + return name === "externcrate"; } // No match From 2a1595e2fea2dfa7f853f07d3595cbd543342d8e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 30 Oct 2025 16:10:53 +0100 Subject: [PATCH 2/2] Add regression test for including extern crates in import filtering --- tests/rustdoc-js/import-filter.js | 20 ++++++++++++++++++++ tests/rustdoc-js/import-filter.rs | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/rustdoc-js/import-filter.js create mode 100644 tests/rustdoc-js/import-filter.rs diff --git a/tests/rustdoc-js/import-filter.js b/tests/rustdoc-js/import-filter.js new file mode 100644 index 0000000000000..408d0e3326179 --- /dev/null +++ b/tests/rustdoc-js/import-filter.js @@ -0,0 +1,20 @@ +// This test ensures that when filtering on `import`, `externcrate` items are also displayed. +// It also ensures that the opposite is not true. + +const EXPECTED = [ + { + 'query': 'import:st', + 'others': [ + { 'path': 'foo', 'name': 'st', 'href': '../foo/index.html#reexport.st' }, + // FIXME: `href` is wrong: + { 'path': 'foo', 'name': 'st2', 'href': '../st2/index.html' }, + ], + }, + { + 'query': 'externcrate:st', + 'others': [ + // FIXME: `href` is wrong: + { 'path': 'foo', 'name': 'st2', 'href': '../st2/index.html' }, + ], + }, +]; diff --git a/tests/rustdoc-js/import-filter.rs b/tests/rustdoc-js/import-filter.rs new file mode 100644 index 0000000000000..7d30d00f5bbf8 --- /dev/null +++ b/tests/rustdoc-js/import-filter.rs @@ -0,0 +1,7 @@ +#![crate_name = "foo"] + +pub extern crate std as st2; + +pub use crate::Bar as st; + +pub struct Bar;