about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbinarycat <binarycat@envs.net>2025-03-24 15:57:07 -0500
committerbinarycat <binarycat@envs.net>2025-03-24 15:57:07 -0500
commitc123adf860b008f703b325d013e7c7c0cc707d56 (patch)
tree3f8b2930e7348e15c5963cc388d25135a4063612
parent90f5eab952728ac6edcf529a171f7de5c25e5d49 (diff)
downloadrust-c123adf860b008f703b325d013e7c7c0cc707d56.tar.gz
rust-c123adf860b008f703b325d013e7c7c0cc707d56.zip
rustdoc js: add nonundef and use it to remove a ts-expect-error
-rw-r--r--src/librustdoc/html/static/js/rustdoc.d.ts4
-rw-r--r--src/librustdoc/html/static/js/search.js7
-rw-r--r--src/librustdoc/html/static/js/storage.js22
3 files changed, 28 insertions, 5 deletions
diff --git a/src/librustdoc/html/static/js/rustdoc.d.ts b/src/librustdoc/html/static/js/rustdoc.d.ts
index e94c6beabea..e2ebb139183 100644
--- a/src/librustdoc/html/static/js/rustdoc.d.ts
+++ b/src/librustdoc/html/static/js/rustdoc.d.ts
@@ -6,8 +6,10 @@
 declare global {
     /** Map from crate name to directory structure, for source view */
     declare var srcIndex: Map<string, rustdoc.Dir>;
-    /** Defined and documented in `main.js` */
+    /** Defined and documented in `storage.js` */
     declare function nonnull(x: T|null, msg: string|undefined);
+    /** Defined and documented in `storage.js` */
+    declare function nonundef(x: T|undefined, msg: string|undefined);
     interface Window {
         /** Make the current theme easy to find */
         currentTheme: HTMLLinkElement|null;
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index c275127997a..decb4807e88 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -1,5 +1,5 @@
 // ignore-tidy-filelength
-/* global addClass, getNakedUrl, getSettingValue, getVar */
+/* global addClass, getNakedUrl, getSettingValue, getVar, nonnull, nonundef */
 /* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi, exports */
 
 "use strict";
@@ -338,9 +338,8 @@ function getFilteredNextElem(query, parserState, elems, isInGenerics) {
         // The type filter doesn't count as an element since it's a modifier.
         const typeFilterElem = elems.pop();
         checkExtraTypeFilterCharacters(start, parserState);
-        // typeFilterElem is not null. If it was, the elems.length check would have fired.
-        // @ts-expect-error
-        parserState.typeFilter = typeFilterElem.normalizedPathLast;
+        // typeFilterElem is not undefined. If it was, the elems.length check would have fired.
+        parserState.typeFilter = nonundef(typeFilterElem).normalizedPathLast;
         parserState.pos += 1;
         parserState.totalElems -= 1;
         query.literalSearch = false;
diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js
index 748d2ef33c3..76113726894 100644
--- a/src/librustdoc/html/static/js/storage.js
+++ b/src/librustdoc/html/static/js/storage.js
@@ -44,6 +44,28 @@ function nonnull(x, msg) {
 }
 
 /**
+ * Assert that the passed value is not undefined, then return it.
+ *
+ * Takes an optional error message argument.
+ *
+ * Must be defined in this file, as it is loaded before all others.
+ *
+ * @template T
+ * @param {T|undefined} x
+ * @param {string=} msg
+ * @returns T
+ */
+// used in other files, not yet used in this one.
+// eslint-disable-next-line no-unused-vars
+function nonundef(x, msg) {
+    if (x === undefined) {
+        throw (msg || "unexpected null value!");
+    } else {
+        return x;
+    }
+}
+
+/**
  * Get a configuration value. If it's not set, get the default.
  *
  * @param {string} settingName