rustdoc-search: single result for items with multiple paths

This change uses the same "exact" paths as trait implementors
and type alias inlining to track items with multiple
reachable paths. This way, if you search for `vec`, you get
only the `std` exports of it, and not the one from `alloc`.

It still includes all the items in the search index so that
you can search for them by all available paths. For example,
try `core::option` and `std::option`, and notice that the
results page doesn't show duplicates, but still shows all
the items in their respective crates.
This commit is contained in:
Michael Howell 2024-01-12 15:32:08 -07:00
parent ab5bda1aa7
commit f36c5af359
13 changed files with 313 additions and 25 deletions

View file

@ -0,0 +1,7 @@
#[macro_use]
mod hidden_macro_module {
#[macro_export]
macro_rules! vec {
() => {};
}
}

View file

@ -0,0 +1,11 @@
// exact-check
const EXPECTED = [
{
'query': 'vec',
'others': [
{ 'path': 'foo', 'name': 'vec', 'exactPath': 'macro_in_module' },
{ 'path': 'foo', 'name': 'myspecialvec', 'exactPath': 'foo' },
],
},
];

View file

@ -0,0 +1,15 @@
//@ aux-crate: macro_in_module=macro-in-module.rs
#![crate_name="foo"]
extern crate macro_in_module;
// Test case based on the relationship between alloc and std.
#[doc(inline)]
pub use macro_in_module::vec;
#[macro_use]
mod hidden_macro_module {
#[macro_export]
macro_rules! myspecialvec {
() => {};
}
}

View file

@ -0,0 +1,16 @@
// exact-check
const EXPECTED = [
{
'query': 'Subscriber dostuff',
'others': [
{ 'path': 'foo::fmt::Subscriber', 'name': 'dostuff' },
],
},
{
'query': 'AnotherOne dostuff',
'others': [
{ 'path': 'foo::AnotherOne', 'name': 'dostuff' },
],
},
];

View file

@ -0,0 +1,18 @@
// This test enforces that the (renamed) reexports are present in the search results.
#![crate_name="foo"]
pub mod fmt {
pub struct Subscriber;
impl Subscriber {
pub fn dostuff(&self) {}
}
}
mod foo {
pub struct AnotherOne;
impl AnotherOne {
pub fn dostuff(&self) {}
}
}
pub use foo::AnotherOne;
pub use fmt::Subscriber;

View file

@ -0,0 +1,22 @@
// exact-check
const EXPECTED = [
{
'query': 'Subscriber',
'others': [
{ 'path': 'foo', 'name': 'Subscriber' },
],
},
{
'query': 'fmt Subscriber',
'others': [
{ 'path': 'foo::fmt', 'name': 'Subscriber' },
],
},
{
'query': 'AnotherOne',
'others': [
{ 'path': 'foo', 'name': 'AnotherOne' },
],
},
];

View file

@ -0,0 +1,12 @@
// This test enforces that the (renamed) reexports are present in the search results.
#![crate_name="foo"]
pub mod fmt {
pub struct Subscriber;
}
mod foo {
pub struct AnotherOne;
}
pub use foo::AnotherOne;
pub use fmt::Subscriber;

View file

@ -1,4 +1,6 @@
// This test enforces that the (renamed) reexports are present in the search results.
// This is a DWIM case, since renaming the export probably means the intent is also different.
// For the de-duplication case of exactly the same name, see reexport-dedup
pub mod fmt {
pub struct Subscriber;