Auto merge of #52764 - sinkuu:cleanup, r=nikomatsakis

Misc cleanups
This commit is contained in:
bors 2018-07-29 06:32:24 +00:00
commit a5c2d0fffa
20 changed files with 50 additions and 73 deletions

View file

@ -16,7 +16,6 @@
//! them in the future to instead emit any format desired.
use std::fmt;
use std::iter::repeat;
use rustc::hir::def_id::DefId;
use rustc_target::spec::abi::Abi;
@ -235,10 +234,9 @@ impl<'a> fmt::Display for WhereClause<'a> {
if !f.alternate() {
clause.push_str("</span>");
let padding = repeat("&nbsp;").take(indent + 4).collect::<String>();
let padding = "&nbsp;".repeat(indent + 4);
clause = clause.replace("<br>", &format!("<br>{}", padding));
clause.insert_str(0, &repeat("&nbsp;").take(indent.saturating_sub(1))
.collect::<String>());
clause.insert_str(0, &"&nbsp;".repeat(indent.saturating_sub(1)));
if !end_newline {
clause.insert_str(0, "<br>");
}
@ -409,13 +407,13 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
Some(&(ref fqp, shortty)) => {
(fqp, shortty, repeat("../").take(loc.len()).collect())
(fqp, shortty, "../".repeat(loc.len()))
}
None => {
let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
(fqp, shortty, match cache.extern_locations[&did.krate] {
(.., render::Remote(ref s)) => s.to_string(),
(.., render::Local) => repeat("../").take(loc.len()).collect(),
(.., render::Local) => "../".repeat(loc.len()),
(.., render::Unknown) => return None,
})
}
@ -481,7 +479,7 @@ fn primitive_link(f: &mut fmt::Formatter,
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
let len = if len == 0 {0} else {len - 1};
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
repeat("../").take(len).collect::<String>(),
"../".repeat(len),
prim.to_url_str())?;
needs_termination = true;
}
@ -492,7 +490,7 @@ fn primitive_link(f: &mut fmt::Formatter,
}
(ref cname, _, render::Local) => {
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
Some((cname, repeat("../").take(len).collect::<String>()))
Some((cname, "../".repeat(len)))
}
(.., render::Unknown) => None,
};
@ -907,15 +905,15 @@ impl<'a> fmt::Display for Method<'a> {
format!("{}", decl.output)
};
let pad = repeat(" ").take(name_len).collect::<String>();
let pad = " ".repeat(name_len);
let plain = format!("{pad}({args}){arrow}",
pad = pad,
args = args_plain,
arrow = arrow_plain);
let output = if plain.len() > 80 {
let full_pad = format!("<br>{}", repeat("&nbsp;").take(indent + 4).collect::<String>());
let close_pad = format!("<br>{}", repeat("&nbsp;").take(indent).collect::<String>());
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
format!("({args}{close}){arrow}",
args = args.replace("<br>", &full_pad),
close = close_pad,

View file

@ -46,7 +46,6 @@ use std::ffi::OsStr;
use std::fs::{self, File, OpenOptions};
use std::io::prelude::*;
use std::io::{self, BufWriter, BufReader};
use std::iter::repeat;
use std::mem;
use std::path::{PathBuf, Path, Component};
use std::str;
@ -1712,7 +1711,7 @@ impl Context {
/// String representation of how to get back to the root path of the 'doc/'
/// folder in terms of a relative URL.
fn root_path(&self) -> String {
repeat("../").take(self.current.len()).collect::<String>()
"../".repeat(self.current.len())
}
/// Recurse in the directory structure and change the "root path" to make
@ -2113,8 +2112,7 @@ impl<'a> fmt::Display for Item<'a> {
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
for (i, component) in cur.iter().enumerate().take(amt) {
write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
repeat("../").take(cur.len() - i - 1)
.collect::<String>(),
"../".repeat(cur.len() - i - 1),
component)?;
}
}