about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2023-12-12 18:48:53 -0800
committerGitHub <noreply@github.com>2023-12-12 18:48:53 -0800
commit2f937c720d5aa6d5218ab7d8c6dc13cc832f7db2 (patch)
tree741a1188ac25d694c3c9a5052fa1a6986e137474 /src/librustdoc/html/static/js
parent5308733112f638d743377b96709a5291c6ae3a37 (diff)
parentf1342f30a5da43a28e25ffccd10ead85f24a7195 (diff)
downloadrust-2f937c720d5aa6d5218ab7d8c6dc13cc832f7db2.tar.gz
rust-2f937c720d5aa6d5218ab7d8c6dc13cc832f7db2.zip
Rollup merge of #118886 - GuillaumeGomez:clean-up-search-vars, r=notriddle
Clean up variables in `search.js`

While reviewing https://github.com/rust-lang/rust/pull/118402, I saw a few small clean ups that were needed, mostly about variables creation.

r? ```@notriddle```
Diffstat (limited to 'src/librustdoc/html/static/js')
-rw-r--r--src/librustdoc/html/static/js/search.js20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index f2875b7f01e..5d348d3f176 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -2100,8 +2100,6 @@ function initSearch(rawSearchIndex) {
         }
 
         function innerRunQuery() {
-            let elem, i, nSearchWords, in_returned, row;
-
             let queryLen = 0;
             for (const elem of parsedQuery.elems) {
                 queryLen += elem.name.length;
@@ -2227,8 +2225,8 @@ function initSearch(rawSearchIndex) {
 
             if (parsedQuery.foundElems === 1) {
                 if (parsedQuery.elems.length === 1) {
-                    elem = parsedQuery.elems[0];
-                    for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
+                    const elem = parsedQuery.elems[0];
+                    for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
                         // It means we want to check for this element everywhere (in names, args and
                         // returned).
                         handleSingleArg(
@@ -2243,10 +2241,9 @@ function initSearch(rawSearchIndex) {
                     }
                 } else if (parsedQuery.returned.length === 1) {
                     // We received one returned argument to check, so looking into returned values.
-                    elem = parsedQuery.returned[0];
-                    for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
-                        row = searchIndex[i];
-                        in_returned = row.type && unifyFunctionTypes(
+                    for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
+                        const row = searchIndex[i];
+                        const in_returned = row.type && unifyFunctionTypes(
                             row.type.output,
                             parsedQuery.returned,
                             row.type.where_clause
@@ -2264,7 +2261,7 @@ function initSearch(rawSearchIndex) {
                     }
                 }
             } else if (parsedQuery.foundElems > 0) {
-                for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
+                for (let i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) {
                     handleArgs(searchIndex[i], i, results_others);
                 }
             }
@@ -2420,7 +2417,6 @@ function initSearch(rawSearchIndex) {
         const extraClass = display ? " active" : "";
 
         const output = document.createElement("div");
-        let length = 0;
         if (array.length > 0) {
             output.className = "search-results " + extraClass;
 
@@ -2430,8 +2426,6 @@ function initSearch(rawSearchIndex) {
                 const longType = longItemTypes[item.ty];
                 const typeName = longType.length !== 0 ? `${longType}` : "?";
 
-                length += 1;
-
                 const link = document.createElement("a");
                 link.className = "result-" + type;
                 link.href = item.href;
@@ -2479,7 +2473,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
                 "href=\"https://docs.rs\">Docs.rs</a> for documentation of crates released on" +
                 " <a href=\"https://crates.io/\">crates.io</a>.</li></ul>";
         }
-        return [output, length];
+        return [output, array.length];
     }
 
     function makeTabHeader(tabNb, text, nbElems) {