about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-11-29 10:11:37 -0700
committerMichael Howell <michael@notriddle.com>2023-11-29 11:02:50 -0700
commitc28de27a73521c0814e771120bd0aeecde67d93b (patch)
treef38e17227278e416ed904863f65c45ae14638c69
parentabe34e9ab14c0a194152b4f9acc3dcbb000f3e98 (diff)
downloadrust-c28de27a73521c0814e771120bd0aeecde67d93b.tar.gz
rust-c28de27a73521c0814e771120bd0aeecde67d93b.zip
rustdoc-search: allow `:: ` and ` ::`
This restriction made sense back when spaces separated function
parameters, but now that they separate path components, there's
no real ambiguity any more.

Additionally, the Rust language allows it.
-rw-r--r--src/librustdoc/html/static/js/search.js13
-rw-r--r--tests/rustdoc-js-std/parser-errors.js27
-rw-r--r--tests/rustdoc-js-std/parser-paths.js48
3 files changed, 62 insertions, 26 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 979aebdb7be..dc6cdcd569a 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -512,18 +512,15 @@ function initSearch(rawSearchIndex) {
                 bindingName,
             };
         }
+        const quadcolon = /::\s*::/.exec(path);
         if (path.startsWith("::")) {
             throw ["Paths cannot start with ", "::"];
         } else if (path.endsWith("::")) {
             throw ["Paths cannot end with ", "::"];
-        } else if (path.includes("::::")) {
-            throw ["Unexpected ", "::::"];
-        } else if (path.includes(" ::")) {
-            throw ["Unexpected ", " ::"];
-        } else if (path.includes(":: ")) {
-            throw ["Unexpected ", ":: "];
-        }
-        const pathSegments = path.split(/::|\s+/);
+        } else if (quadcolon !== null) {
+            throw ["Unexpected ", quadcolon[0]];
+        }
+        const pathSegments = path.split(/(?:::\s*)|(?:\s+(?:::\s*)?)/);
         // In case we only have something like `<p>`, there is no name.
         if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === "")) {
             if (generics.length > 0 || prevIs(parserState, ">")) {
diff --git a/tests/rustdoc-js-std/parser-errors.js b/tests/rustdoc-js-std/parser-errors.js
index ab8d72bf71b..410fe11b9cf 100644
--- a/tests/rustdoc-js-std/parser-errors.js
+++ b/tests/rustdoc-js-std/parser-errors.js
@@ -144,6 +144,15 @@ const PARSED = [
         error: "Unexpected `::::`",
     },
     {
+        query: "a:: ::b",
+        elems: [],
+        foundElems: 0,
+        original: "a:: ::b",
+        returned: [],
+        userQuery: "a:: ::b",
+        error: "Unexpected `:: ::`",
+    },
+    {
         query: "a::b::",
         elems: [],
         foundElems: 0,
@@ -315,24 +324,6 @@ const PARSED = [
         error: 'Unexpected `-` after `<`',
     },
     {
-        query: "a:: a",
-        elems: [],
-        foundElems: 0,
-        original: 'a:: a',
-        returned: [],
-        userQuery: 'a:: a',
-        error: 'Unexpected `:: `',
-    },
-    {
-        query: "a ::a",
-        elems: [],
-        foundElems: 0,
-        original: 'a ::a',
-        returned: [],
-        userQuery: 'a ::a',
-        error: 'Unexpected ` ::`',
-    },
-    {
         query: "a<a>:",
         elems: [],
         foundElems: 0,
diff --git a/tests/rustdoc-js-std/parser-paths.js b/tests/rustdoc-js-std/parser-paths.js
index 8d4dedf3f46..774e5d028cc 100644
--- a/tests/rustdoc-js-std/parser-paths.js
+++ b/tests/rustdoc-js-std/parser-paths.js
@@ -16,6 +16,54 @@ const PARSED = [
         error: null,
     },
     {
+        query: "a:: a",
+        elems: [{
+            name: "a:: a",
+            fullPath: ["a", "a"],
+            pathWithoutLast: ["a"],
+            pathLast: "a",
+            generics: [],
+            typeFilter: -1,
+        }],
+        foundElems: 1,
+        original: 'a:: a',
+        returned: [],
+        userQuery: 'a:: a',
+        error: null,
+    },
+    {
+        query: "a ::a",
+        elems: [{
+            name: "a ::a",
+            fullPath: ["a", "a"],
+            pathWithoutLast: ["a"],
+            pathLast: "a",
+            generics: [],
+            typeFilter: -1,
+        }],
+        foundElems: 1,
+        original: 'a ::a',
+        returned: [],
+        userQuery: 'a ::a',
+        error: null,
+    },
+    {
+        query: "a  ::  a",
+        elems: [{
+            name: "a  ::  a",
+            fullPath: ["a", "a"],
+            pathWithoutLast: ["a"],
+            pathLast: "a",
+            generics: [],
+            typeFilter: -1,
+        }],
+        foundElems: 1,
+        original: 'a  ::  a',
+        returned: [],
+        userQuery: 'a  ::  a',
+        error: null,
+    },
+    {
         query: 'A::B,C',
         elems: [
             {