Skip to content

Commit 21a1213

Browse files
committed
rustdoc: change the "In Function Signatures" to context-sensitive
* If it's just `-> a`, use "In Function Return Types" * If it's just `a b`, use "In Function Parameters" * Otherwise, still use "In Function Signatures"
1 parent 345a580 commit 21a1213

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,12 @@ window.initSearch = rawSearchIndex => {
17241724
makeTabHeader(2, "In Return Types", ret_returned[1]) +
17251725
"</div>";
17261726
} else {
1727+
const signatureTabTitle =
1728+
results.query.elems.length === 0 ? "In Function Return Types" :
1729+
results.query.returned.length === 0 ? "In Function Parameters" :
1730+
"In Function Signatures";
17271731
output += '<div id="titles">' +
1728-
makeTabHeader(0, "In Function Signature", ret_others[1]) +
1732+
makeTabHeader(0, signatureTabTitle, ret_others[1]) +
17291733
"</div>";
17301734
}
17311735

src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@ write: (".search-input", "-> String")
1313
// Waiting for the search results to appear...
1414
wait-for: "#titles"
1515
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
16-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
16+
assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
1717

1818
// Try with a search-by-return with no results
1919
goto: file://|DOC_PATH|/test_docs/index.html
2020
write: (".search-input", "-> Something")
2121
// Waiting for the search results to appear...
2222
wait-for: "#titles"
2323
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
24-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
24+
assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
2525

26-
// Try with a search-by-return with no results
26+
// Try with a search-by-parameter
2727
goto: file://|DOC_PATH|/test_docs/index.html
2828
write: (".search-input", "usize pattern")
2929
// Waiting for the search results to appear...
3030
wait-for: "#titles"
3131
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
32-
assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
32+
assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH)
33+
34+
// Try with a search-by-parameter-and-return
35+
goto: file://|DOC_PATH|/test_docs/index.html
36+
write: (".search-input", "pattern -> str")
37+
// Waiting for the search results to appear...
38+
wait-for: "#titles"
39+
assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
40+
assert-text: ("#titles > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH)

0 commit comments

Comments
 (0)