about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-15 19:32:17 +0000
committerbors <bors@rust-lang.org>2023-12-15 19:32:17 +0000
commita96d57bdb6d2bb6d233d7d5aaefc2995ab99be01 (patch)
treef04bb808893aafc5db3c72834fc747c791aebfdb /src
parent3f39cae1199a2a0217c3646a16d1ae7fa599130b (diff)
parent5fc9ff5619f83689a27126efc0d7f51b9f5d7b2b (diff)
downloadrust-a96d57bdb6d2bb6d233d7d5aaefc2995ab99be01.tar.gz
rust-a96d57bdb6d2bb6d233d7d5aaefc2995ab99be01.zip
Auto merge of #118996 - matthiaskrgr:rollup-n6x2lc7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #117824 (Stabilize `ptr::{from_ref, from_mut}`)
 - #118234 (Stabilize `type_name_of_val`)
 - #118944 (Move type relations into submodule `relate` in rustc_infer, and notify when it has changed)
 - #118977 (Simplify `src-script.js` code)
 - #118985 (Remove `@JohnTitor` from diagnostics pings)
 - #118986 (Simplify JS code a little bit)
 - #118988 (rustdoc: add regression test for JS data file loading)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render/write_shared.rs4
-rw-r--r--src/librustdoc/html/static/js/src-script.js15
2 files changed, 5 insertions, 14 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index c4a6e920031..6408e97df50 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -328,8 +328,8 @@ pub(super) fn write_shared(
         v.push_str(
             r#"\
 ]'));
-if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)};
-if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
+if (typeof exports !== 'undefined') exports.searchIndex = searchIndex;
+else if (window.initSearch) window.initSearch(searchIndex);
 "#,
         );
         Ok(v.into_bytes())
diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js
index bbb0527a833..fc1d2d37845 100644
--- a/src/librustdoc/html/static/js/src-script.js
+++ b/src/librustdoc/html/static/js/src-script.js
@@ -146,12 +146,8 @@ function createSrcSidebar() {
     }
 }
 
-const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
-
-function highlightSrcLines(match) {
-    if (typeof match === "undefined") {
-        match = window.location.hash.match(lineNumbersRegex);
-    }
+function highlightSrcLines() {
+    const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
     if (!match) {
         return;
     }
@@ -233,12 +229,7 @@ const handleSrcHighlight = (function() {
     };
 }());
 
-window.addEventListener("hashchange", () => {
-    const match = window.location.hash.match(lineNumbersRegex);
-    if (match) {
-        return highlightSrcLines(match);
-    }
-});
+window.addEventListener("hashchange", highlightSrcLines);
 
 onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
     el.addEventListener("click", handleSrcHighlight);