about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-05-02 09:45:32 -0700
committerMichael Howell <michael@notriddle.com>2022-05-05 09:37:29 -0700
commit21a121332b4c5e2302c46956564879c447d555b2 (patch)
treed303e29b5900048c765110e9ca334adfe900440b /src
parent345a580e8d19c59cdd7d6ab5889311d2f07d7931 (diff)
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"
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/static/js/search.js6
-rw-r--r--src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml16
2 files changed, 17 insertions, 5 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index f93f21af817..2468d39ebc7 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -1724,8 +1724,12 @@ window.initSearch = rawSearchIndex => {
                 makeTabHeader(2, "In Return Types", ret_returned[1]) +
                 "</div>";
         } else {
+            const signatureTabTitle =
+                results.query.elems.length === 0 ? "In Function Return Types" :
+                results.query.returned.length === 0 ? "In Function Parameters" :
+                "In Function Signatures";
             output += '<div id="titles">' +
-                makeTabHeader(0, "In Function Signature", ret_others[1]) +
+                makeTabHeader(0, signatureTabTitle, ret_others[1]) +
                 "</div>";
         }
 
diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
index 3cf34c2f432..fc6b0696bf0 100644
--- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
+++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
@@ -13,7 +13,7 @@ write: (".search-input", "-> String")
 // Waiting for the search results to appear...
 wait-for: "#titles"
 assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
-assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
+assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
 
 // Try with a search-by-return with no results
 goto: file://|DOC_PATH|/test_docs/index.html
@@ -21,12 +21,20 @@ write: (".search-input", "-> Something")
 // Waiting for the search results to appear...
 wait-for: "#titles"
 assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
-assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
+assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
 
-// Try with a search-by-return with no results
+// Try with a search-by-parameter
 goto: file://|DOC_PATH|/test_docs/index.html
 write: (".search-input", "usize pattern")
 // Waiting for the search results to appear...
 wait-for: "#titles"
 assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
-assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH)
+assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH)
+
+// Try with a search-by-parameter-and-return
+goto: file://|DOC_PATH|/test_docs/index.html
+write: (".search-input", "pattern -> str")
+// Waiting for the search results to appear...
+wait-for: "#titles"
+assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
+assert-text: ("#titles > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH)