about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-04-26 13:58:23 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2022-04-26 20:57:45 +0200
commit45cdb2be10756f584540f349a379730c43fe0976 (patch)
tree313f9461d2006c206ef8db0926ba4d0a7bc675fd
parent082e4ca49770ebc9cb0ee616f3726a67471be8cb (diff)
downloadrust-45cdb2be10756f584540f349a379730c43fe0976.tar.gz
rust-45cdb2be10756f584540f349a379730c43fe0976.zip
Update rustdoc search parser to handle `!` correctly
-rw-r--r--src/librustdoc/html/static/js/search.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index c4e74ea0657..c1d2ec540b0 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -310,10 +310,20 @@ window.initSearch = function(rawSearchIndex) {
      */
     function getIdentEndPosition(parserState) {
         let end = parserState.pos;
+        let foundExclamation = false;
         while (parserState.pos < parserState.length) {
             const c = parserState.userQuery[parserState.pos];
             if (!isIdentCharacter(c)) {
-                if (isErrorCharacter(c)) {
+                if (c === "!") {
+                    if (foundExclamation) {
+                        throw new Error("Cannot have more than one `!` in an ident");
+                    } else if (parserState.pos + 1 < parserState.length &&
+                        isIdentCharacter(parserState.userQuery[parserState.pos + 1]))
+                    {
+                        throw new Error("`!` can only be at the end of an ident");
+                    }
+                    foundExclamation = true;
+                } else if (isErrorCharacter(c)) {
                     throw new Error(`Unexpected \`${c}\``);
                 } else if (
                     isStopCharacter(c) ||
@@ -329,6 +339,7 @@ window.initSearch = function(rawSearchIndex) {
                     }
                     // Skip current ":".
                     parserState.pos += 1;
+                    foundExclamation = false;
                 } else {
                     throw new Error(`Unexpected \`${c}\``);
                 }
@@ -591,7 +602,7 @@ window.initSearch = function(rawSearchIndex) {
      *
      * The supported syntax by this parser is as follow:
      *
-     * ident = *(ALPHA / DIGIT / "_")
+     * ident = *(ALPHA / DIGIT / "_") [!]
      * path = ident *(DOUBLE-COLON ident)
      * arg = path [generics]
      * arg-without-generic = path