1
Fork 0

cleanup: replace as[_mut]_slice() calls with deref coercions

This commit is contained in:
Jorge Aparicio 2015-02-01 21:53:25 -05:00
parent 2c05354211
commit 17bc7d8d5b
289 changed files with 1372 additions and 1406 deletions

View file

@ -447,7 +447,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> old_io::IoResult<Stri
path = "";
} else {
lastpath = item.path.to_string();
path = item.path.as_slice();
path = &item.path;
};
if i > 0 {
@ -525,8 +525,7 @@ fn write_shared(cx: &Context,
if !line.starts_with(key) {
continue
}
if line.starts_with(
format!("{}['{}']", key, krate).as_slice()) {
if line.starts_with(&format!("{}['{}']", key, krate)) {
continue
}
ret.push(line.to_string());
@ -537,8 +536,7 @@ fn write_shared(cx: &Context,
// Update the search index
let dst = cx.dst.join("search-index.js");
let all_indexes = try!(collect(&dst, krate.name.as_slice(),
"searchIndex"));
let all_indexes = try!(collect(&dst, &krate.name, "searchIndex"));
let mut w = try!(File::create(&dst));
try!(writeln!(&mut w, "var searchIndex = {{}};"));
try!(writeln!(&mut w, "{}", search_index));
@ -565,13 +563,13 @@ fn write_shared(cx: &Context,
let mut mydst = dst.clone();
for part in &remote_path[..remote_path.len() - 1] {
mydst.push(part.as_slice());
mydst.push(part);
try!(mkdir(&mydst));
}
mydst.push(format!("{}.{}.js",
remote_item_type.to_static_str(),
remote_path[remote_path.len() - 1]));
let all_implementors = try!(collect(&mydst, krate.name.as_slice(),
let all_implementors = try!(collect(&mydst, &krate.name,
"implementors"));
try!(mkdir(&mydst.dir_path()));
@ -611,7 +609,7 @@ fn render_sources(cx: &mut Context,
info!("emitting source files");
let dst = cx.dst.join("src");
try!(mkdir(&dst));
let dst = dst.join(krate.name.as_slice());
let dst = dst.join(&krate.name);
try!(mkdir(&dst));
let mut folder = SourceCollector {
dst: dst,
@ -662,7 +660,7 @@ fn clean_srcpath<F>(src_root: &Path, src: &[u8], mut f: F) where
if ".." == c {
f("up");
} else {
f(c.as_slice())
f(c)
}
}
}
@ -672,7 +670,7 @@ fn clean_srcpath<F>(src_root: &Path, src: &[u8], mut f: F) where
/// rendering in to the specified source destination.
fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
// See if there's documentation generated into the local directory
let local_location = dst.join(e.name.as_slice());
let local_location = dst.join(&e.name);
if local_location.is_dir() {
return Local;
}
@ -715,9 +713,7 @@ impl<'a> DocFolder for SourceCollector<'a> {
// entire crate. The other option is maintaining this mapping on a
// per-file basis, but that's probably not worth it...
self.cx
.include_sources = match self.emit_source(item.source
.filename
.as_slice()) {
.include_sources = match self.emit_source(&item.source .filename) {
Ok(()) => true,
Err(e) => {
println!("warning: source code was requested to be rendered, \
@ -750,7 +746,7 @@ impl<'a> SourceCollector<'a> {
filename.ends_with("macros>") => return Ok(()),
Err(e) => return Err(e)
};
let contents = str::from_utf8(contents.as_slice()).unwrap();
let contents = str::from_utf8(&contents).unwrap();
// Remove the utf-8 BOM if any
let contents = if contents.starts_with("\u{feff}") {
@ -776,10 +772,10 @@ impl<'a> SourceCollector<'a> {
let title = format!("{} -- source", cur.filename_display());
let desc = format!("Source to the Rust file `{}`.", filename);
let page = layout::Page {
title: title.as_slice(),
title: &title,
ty: "source",
root_path: root_path.as_slice(),
description: desc.as_slice(),
root_path: &root_path,
description: &desc,
keywords: get_basic_keywords(),
};
try!(layout::render(&mut w as &mut Writer, &self.cx.layout,
@ -865,13 +861,13 @@ impl DocFolder for Cache {
Some(&(ref fqp, ItemType::Struct)) |
Some(&(ref fqp, ItemType::Enum)) =>
Some(&fqp[..fqp.len() - 1]),
Some(..) => Some(self.stack.as_slice()),
Some(..) => Some(&*self.stack),
None => None
};
((Some(*last), path), true)
}
}
_ => ((None, Some(self.stack.as_slice())), false)
_ => ((None, Some(&*self.stack)), false)
};
let hidden_field = match item.inner {
clean::StructFieldItem(clean::HiddenStructField) => true,
@ -1059,7 +1055,7 @@ impl Context {
panic!("Unexpected empty destination: {:?}", self.current);
}
let prev = self.dst.clone();
self.dst.push(s.as_slice());
self.dst.push(&s);
self.root_path.push_str("../");
self.current.push(s);
@ -1103,9 +1099,9 @@ impl Context {
this.layout.krate);
let page = layout::Page {
ty: "mod",
root_path: this.root_path.as_slice(),
title: title.as_slice(),
description: desc.as_slice(),
root_path: &this.root_path,
title: &title,
description: &desc,
keywords: get_basic_keywords(),
};
let html_dst = &this.dst.join("stability.html");
@ -1151,7 +1147,7 @@ impl Context {
if title.len() > 0 {
title.push_str("::");
}
title.push_str(it.name.as_ref().unwrap().as_slice());
title.push_str(it.name.as_ref().unwrap());
}
title.push_str(" - Rust");
let tyname = shortty(it).to_static_str();
@ -1169,10 +1165,10 @@ impl Context {
let keywords = make_item_keywords(it);
let page = layout::Page {
ty: tyname,
root_path: cx.root_path.as_slice(),
title: title.as_slice(),
description: desc.as_slice(),
keywords: keywords.as_slice(),
root_path: &cx.root_path,
title: &title,
description: &desc,
keywords: &keywords,
};
markdown::reset_headers();
@ -1191,11 +1187,11 @@ impl Context {
match cache().paths.get(&it.def_id) {
Some(&(ref names, _)) => {
for name in &names[..names.len() - 1] {
url.push_str(name.as_slice());
url.push_str(name);
url.push_str("/");
}
url.push_str(item_path(it).as_slice());
try!(layout::redirect(&mut writer, url.as_slice()));
url.push_str(&item_path(it));
try!(layout::redirect(&mut writer, &url));
}
None => {}
}
@ -1378,17 +1374,17 @@ impl<'a> fmt::Display for Item<'a> {
_ => false,
};
if !is_primitive {
let cur = self.cx.current.as_slice();
let cur = &self.cx.current;
let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() };
for (i, component) in cur.iter().enumerate().take(amt) {
try!(write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
repeat("../").take(cur.len() - i - 1)
.collect::<String>(),
component.as_slice()));
component));
}
}
try!(write!(fmt, "<a class='{}' href=''>{}</a>",
shortty(self.item), self.item.name.as_ref().unwrap().as_slice()));
shortty(self.item), self.item.name.as_ref().unwrap()));
// Write stability level
try!(write!(fmt, "<wbr>{}", Stability(&self.item.stability)));
@ -1433,7 +1429,7 @@ impl<'a> fmt::Display for Item<'a> {
match self.item.inner {
clean::ModuleItem(ref m) => {
item_module(fmt, self.cx, self.item, m.items.as_slice())
item_module(fmt, self.cx, self.item, &m.items)
}
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) =>
item_function(fmt, self.item, f),
@ -1467,7 +1463,7 @@ fn item_path(item: &clean::Item) -> String {
fn full_path(cx: &Context, item: &clean::Item) -> String {
let mut s = cx.current.connect("::");
s.push_str("::");
s.push_str(item.name.as_ref().unwrap().as_slice());
s.push_str(item.name.as_ref().unwrap());
return s
}
@ -1580,12 +1576,12 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
Some(ref src) => {
try!(write!(w, "<tr><td><code>{}extern crate \"{}\" as {};",
VisSpace(myitem.visibility),
src.as_slice(),
name.as_slice()))
src,
name))
}
None => {
try!(write!(w, "<tr><td><code>{}extern crate {};",
VisSpace(myitem.visibility), name.as_slice()))
VisSpace(myitem.visibility), name))
}
}
try!(write!(w, "</code></td></tr>"));
@ -1625,7 +1621,7 @@ impl<'a> fmt::Display for Initializer<'a> {
let Initializer(s) = *self;
if s.len() == 0 { return Ok(()); }
try!(write!(f, "<code> = </code>"));
write!(f, "<code>{}</code>", s.as_slice())
write!(f, "<code>{}</code>", s)
}
}
@ -1634,9 +1630,9 @@ fn item_constant(w: &mut fmt::Formatter, it: &clean::Item,
try!(write!(w, "<pre class='rust const'>{vis}const \
{name}: {typ}{init}</pre>",
vis = VisSpace(it.visibility),
name = it.name.as_ref().unwrap().as_slice(),
name = it.name.as_ref().unwrap(),
typ = c.type_,
init = Initializer(c.expr.as_slice())));
init = Initializer(&c.expr)));
document(w, it)
}
@ -1646,9 +1642,9 @@ fn item_static(w: &mut fmt::Formatter, it: &clean::Item,
{name}: {typ}{init}</pre>",
vis = VisSpace(it.visibility),
mutability = MutableSpace(s.mutability),
name = it.name.as_ref().unwrap().as_slice(),
name = it.name.as_ref().unwrap(),
typ = s.type_,
init = Initializer(s.expr.as_slice())));
init = Initializer(&s.expr)));
document(w, it)
}
@ -1658,7 +1654,7 @@ fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
{name}{generics}{decl}{where_clause}</pre>",
vis = VisSpace(it.visibility),
unsafety = UnsafetySpace(f.unsafety),
name = it.name.as_ref().unwrap().as_slice(),
name = it.name.as_ref().unwrap(),
generics = f.generics,
where_clause = WhereClause(&f.generics),
decl = f.decl));
@ -1675,7 +1671,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
bounds.push_str(": ");
for (i, p) in t.bounds.iter().enumerate() {
if i > 0 { bounds.push_str(" + "); }
bounds.push_str(format!("{}", *p).as_slice());
bounds.push_str(&format!("{}", *p));
}
}
@ -1683,7 +1679,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
try!(write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
VisSpace(it.visibility),
UnsafetySpace(t.unsafety),
it.name.as_ref().unwrap().as_slice(),
it.name.as_ref().unwrap(),
t.generics,
bounds,
WhereClause(&t.generics)));
@ -1823,7 +1819,7 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
_ => "",
},
ty = shortty(it),
name = it.name.as_ref().unwrap().as_slice(),
name = it.name.as_ref().unwrap(),
generics = *g,
decl = Method(selfty, d),
where_clause = WhereClause(g))
@ -1849,7 +1845,7 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
it,
Some(&s.generics),
s.struct_type,
s.fields.as_slice(),
&s.fields,
"",
true));
try!(write!(w, "</pre>"));
@ -1869,7 +1865,7 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
try!(write!(w, "<tr><td id='structfield.{name}'>\
{stab}<code>{name}</code></td><td>",
stab = ConciseStability(&field.stability),
name = field.name.as_ref().unwrap().as_slice()));
name = field.name.as_ref().unwrap()));
try!(document(w, field));
try!(write!(w, "</td></tr>"));
}
@ -1883,7 +1879,7 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
try!(write!(w, "<pre class='rust enum'>{}enum {}{}{}",
VisSpace(it.visibility),
it.name.as_ref().unwrap().as_slice(),
it.name.as_ref().unwrap(),
e.generics,
WhereClause(&e.generics)));
if e.variants.len() == 0 && !e.variants_stripped {
@ -1892,7 +1888,7 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
try!(write!(w, " {{\n"));
for v in &e.variants {
try!(write!(w, " "));
let name = v.name.as_ref().unwrap().as_slice();
let name = v.name.as_ref().unwrap();
match v.inner {
clean::VariantItem(ref var) => {
match var.kind {
@ -1912,7 +1908,7 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
v,
None,
s.struct_type,
s.fields.as_slice(),
&s.fields,
" ",
false));
}
@ -1936,7 +1932,7 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
for variant in &e.variants {
try!(write!(w, "<tr><td id='variant.{name}'>{stab}<code>{name}</code></td><td>",
stab = ConciseStability(&variant.stability),
name = variant.name.as_ref().unwrap().as_slice()));
name = variant.name.as_ref().unwrap()));
try!(document(w, variant));
match variant.inner {
clean::VariantItem(ref var) => {
@ -1957,8 +1953,8 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
try!(write!(w, "<tr><td \
id='variant.{v}.field.{f}'>\
<code>{f}</code></td><td>",
v = variant.name.as_ref().unwrap().as_slice(),
f = field.name.as_ref().unwrap().as_slice()));
v = variant.name.as_ref().unwrap(),
f = field.name.as_ref().unwrap()));
try!(document(w, field));
try!(write!(w, "</td></tr>"));
}
@ -1987,7 +1983,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
try!(write!(w, "{}{}{}",
VisSpace(it.visibility),
if structhead {"struct "} else {""},
it.name.as_ref().unwrap().as_slice()));
it.name.as_ref().unwrap()));
match g {
Some(g) => try!(write!(w, "{}{}", *g, WhereClause(g))),
None => {}
@ -2004,7 +2000,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
clean::StructFieldItem(clean::TypedStructField(ref ty)) => {
try!(write!(w, " {}{}: {},\n{}",
VisSpace(field.visibility),
field.name.as_ref().unwrap().as_slice(),
field.name.as_ref().unwrap(),
*ty,
tab));
}
@ -2091,7 +2087,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
match i.dox {
Some(ref dox) => {
try!(write!(w, "<div class='docblock'>{}</div>",
Markdown(dox.as_slice())));
Markdown(dox)));
}
None => {}
}
@ -2179,7 +2175,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
fn item_typedef(w: &mut fmt::Formatter, it: &clean::Item,
t: &clean::Typedef) -> fmt::Result {
try!(write!(w, "<pre class='rust typedef'>type {}{} = {};</pre>",
it.name.as_ref().unwrap().as_slice(),
it.name.as_ref().unwrap(),
t.generics,
t.type_));
@ -2205,7 +2201,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
fn block(w: &mut fmt::Formatter, short: &str, longty: &str,
cur: &clean::Item, cx: &Context) -> fmt::Result {
let items = match cx.sidebar.get(short) {
Some(items) => items.as_slice(),
Some(items) => items,
None => return Ok(())
};
try!(write!(w, "<div class='block {}'><h2>{}</h2>", short, longty));
@ -2219,12 +2215,12 @@ impl<'a> fmt::Display for Sidebar<'a> {
class = class,
href = if curty == "mod" {"../"} else {""},
path = if short == "mod" {
format!("{}/index.html", name.as_slice())
format!("{}/index.html", name)
} else {
format!("{}.{}.html", short, name.as_slice())
format!("{}.{}.html", short, name)
},
title = Escape(doc.as_ref().unwrap().as_slice()),
name = name.as_slice()));
title = Escape(doc.as_ref().unwrap()),
name = name));
}
try!(write!(w, "</div>"));
Ok(())
@ -2255,16 +2251,16 @@ impl<'a> fmt::Display for Source<'a> {
try!(write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols));
}
try!(write!(fmt, "</pre>"));
try!(write!(fmt, "{}", highlight::highlight(s.as_slice(), None, None)));
try!(write!(fmt, "{}", highlight::highlight(s, None, None)));
Ok(())
}
}
fn item_macro(w: &mut fmt::Formatter, it: &clean::Item,
t: &clean::Macro) -> fmt::Result {
try!(w.write_str(highlight::highlight(t.source.as_slice(),
try!(w.write_str(&highlight::highlight(&t.source,
Some("macro"),
None).as_slice()));
None)));
document(w, it)
}