1
Fork 0

Auto merge of #48755 - GuillaumeGomez:rustdoc-fixes, r=QuietMisdreavus

Multiple rustdoc fixes

Fixes #48733.

r? @QuietMisdreavus
This commit is contained in:
bors 2018-03-10 08:24:08 +00:00
commit 948e3a30e6
4 changed files with 96 additions and 63 deletions

View file

@ -3521,11 +3521,9 @@ impl<'a> fmt::Display for Sidebar<'a> {
let cx = self.cx; let cx = self.cx;
let it = self.item; let it = self.item;
let parentlen = cx.current.len() - if it.is_mod() {1} else {0}; 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() 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, "<p class='location'>")?; write!(fmt, "<p class='location'>")?;
match it.inner { match it.inner {
clean::StructItem(..) => write!(fmt, "Struct ")?, clean::StructItem(..) => write!(fmt, "Struct ")?,
@ -3544,6 +3542,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
} }
write!(fmt, "{}", it.name.as_ref().unwrap())?; write!(fmt, "{}", it.name.as_ref().unwrap())?;
write!(fmt, "</p>")?; write!(fmt, "</p>")?;
}
if it.is_crate() { if it.is_crate() {
if let Some(ref version) = cache().crate_version { if let Some(ref version) = cache().crate_version {
@ -3556,7 +3555,6 @@ impl<'a> fmt::Display for Sidebar<'a> {
} }
write!(fmt, "<div class=\"sidebar-elems\">")?; write!(fmt, "<div class=\"sidebar-elems\">")?;
should_close = true;
match it.inner { match it.inner {
clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?, clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?,
clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?, clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?,
@ -3568,7 +3566,6 @@ impl<'a> fmt::Display for Sidebar<'a> {
clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?, clean::ForeignTypeItem => sidebar_foreign_type(fmt, it)?,
_ => (), _ => (),
} }
}
// The sidebar is designed to display sibling functions, modules and // The sidebar is designed to display sibling functions, modules and
// other miscellaneous information. since there are lots of sibling // other miscellaneous information. since there are lots of sibling
@ -3607,10 +3604,8 @@ impl<'a> fmt::Display for Sidebar<'a> {
write!(fmt, "<script defer src=\"{path}sidebar-items.js\"></script>", write!(fmt, "<script defer src=\"{path}sidebar-items.js\"></script>",
path = relpath)?; path = relpath)?;
} }
if should_close {
// Closes sidebar-elems div. // Closes sidebar-elems div.
write!(fmt, "</div>")?; write!(fmt, "</div>")?;
}
Ok(()) Ok(())
} }

View file

@ -240,12 +240,15 @@
} }
function handleShortcut(ev) { function handleShortcut(ev) {
if (document.activeElement.tagName === "INPUT") if (document.activeElement.tagName === "INPUT" &&
hasClass(document.getElementById('main'), "hidden")) {
return; return;
}
// Don't interfere with browser shortcuts // Don't interfere with browser shortcuts
if (ev.ctrlKey || ev.altKey || ev.metaKey) if (ev.ctrlKey || ev.altKey || ev.metaKey) {
return; return;
}
var help = document.getElementById("help"); var help = document.getElementById("help");
switch (getVirtualKey(ev)) { switch (getVirtualKey(ev)) {
@ -1457,6 +1460,7 @@
// Draw a convenient sidebar of known crates if we have a listing // Draw a convenient sidebar of known crates if we have a listing
if (rootPath === '../') { if (rootPath === '../') {
var sidebar = document.getElementsByClassName('sidebar-elems')[0]; var sidebar = document.getElementsByClassName('sidebar-elems')[0];
if (sidebar) {
var div = document.createElement('div'); var div = document.createElement('div');
div.className = 'block crate'; div.className = 'block crate';
div.innerHTML = '<h3>Crates</h3>'; div.innerHTML = '<h3>Crates</h3>';
@ -1489,6 +1493,7 @@
sidebar.appendChild(div); sidebar.appendChild(div);
} }
} }
}
window.initSearch = initSearch; window.initSearch = initSearch;
@ -1776,6 +1781,18 @@
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); 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'); var toggle = document.createElement('a');
toggle.href = 'javascript:void(0)'; toggle.href = 'javascript:void(0)';
toggle.className = 'collapse-toggle'; toggle.className = 'collapse-toggle';
@ -1786,12 +1803,11 @@
if (!next) { if (!next) {
return; return;
} }
if (hasClass(next, 'docblock') || if ((checkIfThereAreMethods(next.childNodes) || hasClass(e, 'method')) &&
(hasClass(next, 'docblock') ||
hasClass(e, 'impl') ||
(hasClass(next, 'stability') && (hasClass(next, 'stability') &&
hasClass(next.nextElementSibling, 'docblock'))) { hasClass(next.nextElementSibling, 'docblock')))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
if (hasClass(e, 'impl')) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]); insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
} }
} }

View file

@ -528,6 +528,9 @@ a {
.anchor.field { .anchor.field {
left: -5px; left: -5px;
} }
.small-section-header > .anchor {
left: -28px;
}
.anchor:before { .anchor:before {
content: '\2002\00a7\2002'; content: '\2002\00a7\2002';
} }

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;