diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index e7bb0b03ce248..96bba956c5d55 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -3500,11 +3500,9 @@ impl<'a> fmt::Display for Sidebar<'a> {
let cx = self.cx;
let it = self.item;
let parentlen = cx.current.len() - if it.is_mod() {1} else {0};
- let mut should_close = false;
if it.is_struct() || it.is_trait() || it.is_primitive() || it.is_union()
- || it.is_enum() || it.is_mod() || it.is_typedef()
- {
+ || it.is_enum() || it.is_mod() || it.is_typedef() {
write!(fmt, "
")?;
match it.inner {
clean::StructItem(..) => write!(fmt, "Struct ")?,
@@ -3523,30 +3521,29 @@ impl<'a> fmt::Display for Sidebar<'a> {
}
write!(fmt, "{}", it.name.as_ref().unwrap())?;
write!(fmt, "
")?;
+ }
- if it.is_crate() {
- if let Some(ref version) = cache().crate_version {
- write!(fmt,
- "",
- version)?;
- }
+ if it.is_crate() {
+ if let Some(ref version) = cache().crate_version {
+ write!(fmt,
+ "",
+ version)?;
}
+ }
- write!(fmt, "")?;
Ok(())
}
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 960f2f198d8b0..f1c9c58a4ebcf 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -240,12 +240,15 @@
}
function handleShortcut(ev) {
- if (document.activeElement.tagName === "INPUT")
+ if (document.activeElement.tagName === "INPUT" &&
+ hasClass(document.getElementById('main'), "hidden")) {
return;
+ }
// Don't interfere with browser shortcuts
- if (ev.ctrlKey || ev.altKey || ev.metaKey)
+ if (ev.ctrlKey || ev.altKey || ev.metaKey) {
return;
+ }
var help = document.getElementById("help");
switch (getVirtualKey(ev)) {
@@ -1457,36 +1460,38 @@
// Draw a convenient sidebar of known crates if we have a listing
if (rootPath === '../') {
var sidebar = document.getElementsByClassName('sidebar-elems')[0];
- var div = document.createElement('div');
- div.className = 'block crate';
- div.innerHTML = 'Crates
';
- var ul = document.createElement('ul');
- div.appendChild(ul);
-
- var crates = [];
- for (var crate in rawSearchIndex) {
- if (!rawSearchIndex.hasOwnProperty(crate)) {
- continue;
+ if (sidebar) {
+ var div = document.createElement('div');
+ div.className = 'block crate';
+ div.innerHTML = 'Crates
';
+ var ul = document.createElement('ul');
+ div.appendChild(ul);
+
+ var crates = [];
+ for (var crate in rawSearchIndex) {
+ if (!rawSearchIndex.hasOwnProperty(crate)) {
+ continue;
+ }
+ crates.push(crate);
}
- crates.push(crate);
- }
- crates.sort();
- for (var i = 0; i < crates.length; ++i) {
- var klass = 'crate';
- if (crates[i] === window.currentCrate) {
- klass += ' current';
+ crates.sort();
+ for (var i = 0; i < crates.length; ++i) {
+ var klass = 'crate';
+ if (crates[i] === window.currentCrate) {
+ klass += ' current';
+ }
+ var link = document.createElement('a');
+ link.href = '../' + crates[i] + '/index.html';
+ link.title = rawSearchIndex[crates[i]].doc;
+ link.className = klass;
+ link.textContent = crates[i];
+
+ var li = document.createElement('li');
+ li.appendChild(link);
+ ul.appendChild(li);
}
- var link = document.createElement('a');
- link.href = '../' + crates[i] + '/index.html';
- link.title = rawSearchIndex[crates[i]].doc;
- link.className = klass;
- link.textContent = crates[i];
-
- var li = document.createElement('li');
- li.appendChild(link);
- ul.appendChild(li);
+ sidebar.appendChild(div);
}
- sidebar.appendChild(div);
}
}
@@ -1776,22 +1781,33 @@
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
+ function checkIfThereAreMethods(elems) {
+ var areThereMethods = false;
+
+ onEach(elems, function(e) {
+ if (hasClass(e, "method")) {
+ areThereMethods = true;
+ return true;
+ }
+ });
+ return areThereMethods;
+ }
+
var toggle = document.createElement('a');
toggle.href = 'javascript:void(0)';
toggle.className = 'collapse-toggle';
- toggle.innerHTML = "["+labelForToggleButton(false)+"]";
+ toggle.innerHTML = "[" + labelForToggleButton(false) + "]";
var func = function(e) {
var next = e.nextElementSibling;
if (!next) {
return;
}
- if (hasClass(next, 'docblock') ||
- (hasClass(next, 'stability') &&
- hasClass(next.nextElementSibling, 'docblock'))) {
- insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
- }
- if (hasClass(e, 'impl')) {
+ if ((checkIfThereAreMethods(next.childNodes) || hasClass(e, 'method')) &&
+ (hasClass(next, 'docblock') ||
+ hasClass(e, 'impl') ||
+ (hasClass(next, 'stability') &&
+ hasClass(next.nextElementSibling, 'docblock')))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
}
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index b70dc37fdd55e..8060fbc1ee043 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -528,6 +528,9 @@ a {
.anchor.field {
left: -5px;
}
+.small-section-header > .anchor {
+ left: -28px;
+}
.anchor:before {
content: '\2002\00a7\2002';
}
diff --git a/src/test/rustdoc/fn-sidebar.rs b/src/test/rustdoc/fn-sidebar.rs
new file mode 100644
index 0000000000000..4da277a204b71
--- /dev/null
+++ b/src/test/rustdoc/fn-sidebar.rs
@@ -0,0 +1,19 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 or the MIT license
+// , at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+// @has foo/fn.bar.html
+// @has - '//*[@class="sidebar-elems"]' ''
+pub fn bar() {}
+
+// @has foo/constant.BAR.html
+// @has - '//*[@class="sidebar-elems"]' ''
+pub const BAR: u32 = 0;