diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e7bb0b03ce2..96bba956c5d 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 {}

\ -
", - version)?; - } + if it.is_crate() { + if let Some(ref version) = cache().crate_version { + write!(fmt, + "
\ +

Version {}

\ +
", + version)?; } + } - write!(fmt, "
")?; - should_close = true; - match it.inner { - clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?, - clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?, - clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?, - clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?, - clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?, - clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?, - clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?, - clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?, - _ => (), - } + write!(fmt, "
")?; + match it.inner { + clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?, + clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?, + clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?, + clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?, + clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?, + clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?, + clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?, + clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?, + _ => (), } // The sidebar is designed to display sibling functions, modules and @@ -3586,10 +3583,8 @@ impl<'a> fmt::Display for Sidebar<'a> { write!(fmt, "", path = relpath)?; } - if should_close { - // Closes sidebar-elems div. - write!(fmt, "
")?; - } + // Closes sidebar-elems div. + write!(fmt, "
")?; Ok(()) } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 36ca1e06f24..3f74ffbbe0b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1457,36 +1457,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); + 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; + 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'; - } - var link = document.createElement('a'); - link.href = '../' + crates[i] + '/index.html'; - link.title = rawSearchIndex[crates[i]].doc; - link.className = klass; - link.textContent = crates[i]; + 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 li = document.createElement('li'); + li.appendChild(link); + ul.appendChild(li); + } + sidebar.appendChild(div); } - sidebar.appendChild(div); } } diff --git a/src/test/rustdoc/fn-sidebar.rs b/src/test/rustdoc/fn-sidebar.rs new file mode 100644 index 00000000000..4da277a204b --- /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;