Skip to content

Commit 6235ef0

Browse files
Add missing items in the sidebar for functions
1 parent a628543 commit 6235ef0

File tree

3 files changed

+71
-55
lines changed

3 files changed

+71
-55
lines changed

src/librustdoc/html/render.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,11 +3500,9 @@ impl<'a> fmt::Display for Sidebar<'a> {
35003500
let cx = self.cx;
35013501
let it = self.item;
35023502
let parentlen = cx.current.len() - if it.is_mod() {1} else {0};
3503-
let mut should_close = false;
35043503

35053504
if it.is_struct() || it.is_trait() || it.is_primitive() || it.is_union()
3506-
|| it.is_enum() || it.is_mod() || it.is_typedef()
3507-
{
3505+
|| it.is_enum() || it.is_mod() || it.is_typedef() {
35083506
write!(fmt, "<p class='location'>")?;
35093507
match it.inner {
35103508
clean::StructItem(..) => write!(fmt, "Struct ")?,
@@ -3523,30 +3521,29 @@ impl<'a> fmt::Display for Sidebar<'a> {
35233521
}
35243522
write!(fmt, "{}", it.name.as_ref().unwrap())?;
35253523
write!(fmt, "</p>")?;
3524+
}
35263525

3527-
if it.is_crate() {
3528-
if let Some(ref version) = cache().crate_version {
3529-
write!(fmt,
3530-
"<div class='block version'>\
3531-
<p>Version {}</p>\
3532-
</div>",
3533-
version)?;
3534-
}
3526+
if it.is_crate() {
3527+
if let Some(ref version) = cache().crate_version {
3528+
write!(fmt,
3529+
"<div class='block version'>\
3530+
<p>Version {}</p>\
3531+
</div>",
3532+
version)?;
35353533
}
3534+
}
35363535

3537-
write!(fmt, "<div class=\"sidebar-elems\">")?;
3538-
should_close = true;
3539-
match it.inner {
3540-
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
3541-
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
3542-
clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?,
3543-
clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?,
3544-
clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?,
3545-
clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?,
3546-
clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?,
3547-
clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?,
3548-
_ => (),
3549-
}
3536+
write!(fmt, "<div class=\"sidebar-elems\">")?;
3537+
match it.inner {
3538+
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
3539+
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
3540+
clean::PrimitiveItem(ref p) => sidebar_primitive(fmt, it, p)?,
3541+
clean::UnionItem(ref u) => sidebar_union(fmt, it, u)?,
3542+
clean::EnumItem(ref e) => sidebar_enum(fmt, it, e)?,
3543+
clean::TypedefItem(ref t, _) => sidebar_typedef(fmt, it, t)?,
3544+
clean::ModuleItem(ref m) => sidebar_module(fmt, it, &m.items)?,
3545+
clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?,
3546+
_ => (),
35503547
}
35513548

35523549
// The sidebar is designed to display sibling functions, modules and
@@ -3586,10 +3583,8 @@ impl<'a> fmt::Display for Sidebar<'a> {
35863583
write!(fmt, "<script defer src=\"{path}sidebar-items.js\"></script>",
35873584
path = relpath)?;
35883585
}
3589-
if should_close {
3590-
// Closes sidebar-elems div.
3591-
write!(fmt, "</div>")?;
3592-
}
3586+
// Closes sidebar-elems div.
3587+
write!(fmt, "</div>")?;
35933588

35943589
Ok(())
35953590
}

src/librustdoc/html/static/main.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,36 +1457,38 @@
14571457
// Draw a convenient sidebar of known crates if we have a listing
14581458
if (rootPath === '../') {
14591459
var sidebar = document.getElementsByClassName('sidebar-elems')[0];
1460-
var div = document.createElement('div');
1461-
div.className = 'block crate';
1462-
div.innerHTML = '<h3>Crates</h3>';
1463-
var ul = document.createElement('ul');
1464-
div.appendChild(ul);
1465-
1466-
var crates = [];
1467-
for (var crate in rawSearchIndex) {
1468-
if (!rawSearchIndex.hasOwnProperty(crate)) {
1469-
continue;
1460+
if (sidebar) {
1461+
var div = document.createElement('div');
1462+
div.className = 'block crate';
1463+
div.innerHTML = '<h3>Crates</h3>';
1464+
var ul = document.createElement('ul');
1465+
div.appendChild(ul);
1466+
1467+
var crates = [];
1468+
for (var crate in rawSearchIndex) {
1469+
if (!rawSearchIndex.hasOwnProperty(crate)) {
1470+
continue;
1471+
}
1472+
crates.push(crate);
14701473
}
1471-
crates.push(crate);
1472-
}
1473-
crates.sort();
1474-
for (var i = 0; i < crates.length; ++i) {
1475-
var klass = 'crate';
1476-
if (crates[i] === window.currentCrate) {
1477-
klass += ' current';
1474+
crates.sort();
1475+
for (var i = 0; i < crates.length; ++i) {
1476+
var klass = 'crate';
1477+
if (crates[i] === window.currentCrate) {
1478+
klass += ' current';
1479+
}
1480+
var link = document.createElement('a');
1481+
link.href = '../' + crates[i] + '/index.html';
1482+
link.title = rawSearchIndex[crates[i]].doc;
1483+
link.className = klass;
1484+
link.textContent = crates[i];
1485+
1486+
var li = document.createElement('li');
1487+
li.appendChild(link);
1488+
ul.appendChild(li);
14781489
}
1479-
var link = document.createElement('a');
1480-
link.href = '../' + crates[i] + '/index.html';
1481-
link.title = rawSearchIndex[crates[i]].doc;
1482-
link.className = klass;
1483-
link.textContent = crates[i];
1484-
1485-
var li = document.createElement('li');
1486-
li.appendChild(link);
1487-
ul.appendChild(li);
1490+
sidebar.appendChild(div);
14881491
}
1489-
sidebar.appendChild(div);
14901492
}
14911493
}
14921494

src/test/rustdoc/fn-sidebar.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// @has foo/fn.bar.html
14+
// @has - '//*[@class="sidebar-elems"]' ''
15+
pub fn bar() {}
16+
17+
// @has foo/constant.BAR.html
18+
// @has - '//*[@class="sidebar-elems"]' ''
19+
pub const BAR: u32 = 0;

0 commit comments

Comments
 (0)