From c70eb4b6eaeb0256422d32bed949b15ecc37bac9 Mon Sep 17 00:00:00 2001
From: Guillaume Gomez <guillaume1.gomez@gmail.com>
Date: Sun, 5 Aug 2018 18:22:44 +0200
Subject: [PATCH] Automatically expand section if url id point to one of its
 component

---
 src/librustdoc/html/static/main.js | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 62ef5626ee5bb..07507047dc2c9 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -2208,6 +2208,25 @@
     };
 
     autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
+
+    if (window.location.hash && window.location.hash.length > 0) {
+        var hash = getPageId();
+        if (hash !== null) {
+            var elem = document.getElementById(hash);
+            if (elem && elem.offsetParent === null) {
+                console.log(elem, elem.parentNode);
+                if (elem.parentNode && elem.parentNode.previousSibling) {
+                    var collapses = elem.parentNode
+                                        .previousSibling
+                                        .getElementsByClassName("collapse-toggle");
+                    if (collapses.length > 0) {
+                        // The element is not visible, we need to make it appear!
+                        collapseDocs(collapses[0], "show");
+                    }
+                }
+            }
+        }
+    }
 }());
 
 // Sets the focus on the search bar at the top of the page