Skip to content

Commit 4b29f42

Browse files
authored
Rollup merge of #128693 - notriddle:notriddle/impl-disambiguator-2024, r=GuillaumeGomez
rustdoc-search: account for numeric disambiguators on impls Fixes #128676
2 parents fb54b45 + 3a18325 commit 4b29f42

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

src/librustdoc/html/static/js/main.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,24 +390,30 @@ function preLoadCss(cssUrl) {
390390
if (splitAt !== -1) {
391391
const implId = savedHash.slice(0, splitAt);
392392
const assocId = savedHash.slice(splitAt + 1);
393-
const implElem = document.getElementById(implId);
394-
if (implElem && implElem.parentElement.tagName === "SUMMARY" &&
395-
implElem.parentElement.parentElement.tagName === "DETAILS") {
396-
onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
393+
const implElems = document.querySelectorAll(
394+
`details > summary > section[id^="${implId}"]`,
395+
);
396+
onEachLazy(implElems, implElem => {
397+
const numbered = /^(.+?)-([0-9]+)$/.exec(implElem.id);
398+
if (implElem.id !== implId && (!numbered || numbered[1] !== implId)) {
399+
return false;
400+
}
401+
return onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
397402
`[id^="${assocId}"]`),
398403
item => {
399-
const numbered = /([^-]+)-([0-9]+)/.exec(item.id);
404+
const numbered = /^(.+?)-([0-9]+)$/.exec(item.id);
400405
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
401406
openParentDetails(item);
402407
item.scrollIntoView();
403408
// Let the section expand itself before trying to highlight
404409
setTimeout(() => {
405410
window.location.replace("#" + item.id);
406411
}, 0);
412+
return true;
407413
}
408414
},
409415
);
410-
}
416+
});
411417
}
412418
}
413419
}

tests/rustdoc-gui/search-result-impl-disambiguation.goml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,24 @@ assert-document-property: ({
4141
"URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation-1"
4242
}, ENDS_WITH)
4343
assert: "section:target"
44+
45+
// Checks that, if a type has two methods with the same name,
46+
// and if it has multiple inherent impl blocks, that the numeric
47+
// impl block's disambiguator is also acted upon.
48+
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=MultiImplBlockStruct->bool"
49+
wait-for: "#search-tabs"
50+
assert-count: ("a.result-method", 1)
51+
assert-attribute: ("a.result-method", {
52+
"href": "../lib2/another_mod/struct.MultiImplBlockStruct.html#impl-MultiImplBlockStruct/method.second_fn"
53+
})
54+
click: "a.result-method"
55+
wait-for: "details:has(summary > #impl-MultiImplBlockStruct-1) > div section[id='method.second_fn']:target"
56+
57+
go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=MultiImplBlockStruct->u32"
58+
wait-for: "#search-tabs"
59+
assert-count: ("a.result-method", 1)
60+
assert-attribute: ("a.result-method", {
61+
"href": "../lib2/another_mod/struct.MultiImplBlockStruct.html#impl-MultiImplBlockTrait-for-MultiImplBlockStruct/method.second_fn"
62+
})
63+
click: "a.result-method"
64+
wait-for: "details:has(summary > #impl-MultiImplBlockTrait-for-MultiImplBlockStruct) > div section[id='method.second_fn-1']:target"
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
pub fn tadam() {}
1+
pub struct MultiImplBlockStruct;
2+
3+
impl MultiImplBlockStruct {
4+
pub fn first_fn() {}
5+
}
6+
7+
impl MultiImplBlockStruct {
8+
pub fn second_fn(self) -> bool { true }
9+
}
10+
11+
pub trait MultiImplBlockTrait {
12+
fn first_fn();
13+
fn second_fn(self) -> u32;
14+
}
15+
16+
impl MultiImplBlockTrait for MultiImplBlockStruct {
17+
fn first_fn() {}
18+
fn second_fn(self) -> u32 { 1 }
19+
}

0 commit comments

Comments
 (0)