Skip to content
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

rustdoc-search: account for numeric disambiguators on impls #128693

Merged
merged 1 commit into from
Aug 7, 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
18 changes: 12 additions & 6 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,30 @@ function preLoadCss(cssUrl) {
if (splitAt !== -1) {
const implId = savedHash.slice(0, splitAt);
const assocId = savedHash.slice(splitAt + 1);
const implElem = document.getElementById(implId);
if (implElem && implElem.parentElement.tagName === "SUMMARY" &&
implElem.parentElement.parentElement.tagName === "DETAILS") {
onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
const implElems = document.querySelectorAll(
notriddle marked this conversation as resolved.
Show resolved Hide resolved
`details > summary > section[id^="${implId}"]`,
);
onEachLazy(implElems, implElem => {
const numbered = /^(.+?)-([0-9]+)$/.exec(implElem.id);
if (implElem.id !== implId && (!numbered || numbered[1] !== implId)) {
return false;
}
return onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
`[id^="${assocId}"]`),
item => {
const numbered = /([^-]+)-([0-9]+)/.exec(item.id);
const numbered = /^(.+?)-([0-9]+)$/.exec(item.id);
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
openParentDetails(item);
item.scrollIntoView();
// Let the section expand itself before trying to highlight
setTimeout(() => {
window.location.replace("#" + item.id);
}, 0);
return true;
}
},
);
}
});
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/rustdoc-gui/search-result-impl-disambiguation.goml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ assert-document-property: ({
"URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation-1"
}, ENDS_WITH)
assert: "section:target"

// Checks that, if a type has two methods with the same name,
// and if it has multiple inherent impl blocks, that the numeric
// impl block's disambiguator is also acted upon.
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=MultiImplBlockStruct->bool"
wait-for: "#search-tabs"
assert-count: ("a.result-method", 1)
assert-attribute: ("a.result-method", {
"href": "../lib2/another_mod/struct.MultiImplBlockStruct.html#impl-MultiImplBlockStruct/method.second_fn"
})
click: "a.result-method"
wait-for: "details:has(summary > #impl-MultiImplBlockStruct-1) > div section[id='method.second_fn']:target"

go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=MultiImplBlockStruct->u32"
wait-for: "#search-tabs"
assert-count: ("a.result-method", 1)
assert-attribute: ("a.result-method", {
"href": "../lib2/another_mod/struct.MultiImplBlockStruct.html#impl-MultiImplBlockTrait-for-MultiImplBlockStruct/method.second_fn"
})
click: "a.result-method"
wait-for: "details:has(summary > #impl-MultiImplBlockTrait-for-MultiImplBlockStruct) > div section[id='method.second_fn-1']:target"
20 changes: 19 additions & 1 deletion tests/rustdoc-gui/src/lib2/another_mod/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
pub fn tadam() {}
pub struct MultiImplBlockStruct;

impl MultiImplBlockStruct {
pub fn first_fn() {}
}

impl MultiImplBlockStruct {
pub fn second_fn(self) -> bool { true }
}

pub trait MultiImplBlockTrait {
fn first_fn();
fn second_fn(self) -> u32;
}

impl MultiImplBlockTrait for MultiImplBlockStruct {
fn first_fn() {}
fn second_fn(self) -> u32 { 1 }
}
Loading