Skip to content

rustdoc-search: fix mismatched path when parent re-exported twice #134231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ pub(crate) fn build_index(
}
Some(path)
});
} else if let Some(parent_idx) = item.parent_idx {
let i = <isize as TryInto<usize>>::try_into(parent_idx).unwrap();
item.path = {
let p = &crate_paths[i].1;
join_with_double_colon(&p[..p.len() - 1])
};
item.exact_path =
crate_paths[i].2.as_ref().map(|xp| join_with_double_colon(&xp[..xp.len() - 1]));
}

// Omit the parent path if it is same to that of the prior item.
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-js-std/osstring-to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
const EXPECTED = {
'query': 'OsString -> String',
'others': [
{ 'path': 'std::ffi::os_str::OsString', 'name': 'into_string' },
{ 'path': 'std::ffi::OsString', 'name': 'into_string' },
]
};
9 changes: 9 additions & 0 deletions tests/rustdoc-js/reexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ const EXPECTED = [
{ 'path': 'reexport', 'name': 'AnotherOne' },
],
},
{
'query': 'fn:Equivalent::equivalent',
'others': [
// These results must never contain `reexport::equivalent::NotEquivalent`,
// since that path does not exist.
{ 'path': 'equivalent::Equivalent', 'name': 'equivalent' },
{ 'path': 'reexport::NotEquivalent', 'name': 'equivalent' },
],
},
];
9 changes: 9 additions & 0 deletions tests/rustdoc-js/reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
// 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

//@ aux-crate:equivalent=equivalent.rs
//@ compile-flags: --extern equivalent
//@ aux-build:equivalent.rs
//@ build-aux-docs
#[doc(inline)]
pub extern crate equivalent;
#[doc(inline)]
pub use equivalent::Equivalent as NotEquivalent;

pub mod fmt {
pub struct Subscriber;
}
Expand Down
Loading