Remove unnecessary allocations flagged by lint from rustdoc
This commit is contained in:
parent
5a3e320514
commit
d543354d6c
9 changed files with 36 additions and 36 deletions
|
@ -26,7 +26,7 @@ fn doc_metas(
|
|||
attrs: ~[ast::attribute]
|
||||
) -> ~[@ast::meta_item] {
|
||||
|
||||
let doc_attrs = attr::find_attrs_by_name(attrs, ~"doc");
|
||||
let doc_attrs = attr::find_attrs_by_name(attrs, "doc");
|
||||
let doc_metas = do doc_attrs.map |attr| {
|
||||
attr::attr_meta(attr::desugar_doc_attr(attr))
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ fn doc_metas(
|
|||
|
||||
pub fn parse_crate(attrs: ~[ast::attribute]) -> CrateAttrs {
|
||||
let link_metas = attr::find_linkage_metas(attrs);
|
||||
let name = attr::last_meta_item_value_str_by_name(link_metas, ~"name");
|
||||
let name = attr::last_meta_item_value_str_by_name(link_metas, "name");
|
||||
|
||||
CrateAttrs {
|
||||
name: name.map(|s| copy **s)
|
||||
|
@ -58,7 +58,7 @@ pub fn parse_hidden(attrs: ~[ast::attribute]) -> bool {
|
|||
do doc_metas(attrs).find |meta| {
|
||||
match attr::get_meta_item_list(*meta) {
|
||||
Some(metas) => {
|
||||
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
|
||||
let hiddens = attr::find_meta_items_by_name(metas, "hidden");
|
||||
!hiddens.is_empty()
|
||||
}
|
||||
None => false
|
||||
|
|
|
@ -70,12 +70,12 @@ fn opts() -> ~[(getopts::Opt, ~str)] {
|
|||
pub fn usage() {
|
||||
use core::io::println;
|
||||
|
||||
println(~"Usage: rustdoc [options] <cratefile>\n");
|
||||
println(~"Options:\n");
|
||||
println("Usage: rustdoc [options] <cratefile>\n");
|
||||
println("Options:\n");
|
||||
for opts().each |opt| {
|
||||
println(fmt!(" %s", opt.second()));
|
||||
}
|
||||
println(~"");
|
||||
println("");
|
||||
}
|
||||
|
||||
pub fn default_config(input_crate: &Path) -> Config {
|
||||
|
@ -227,7 +227,7 @@ pub fn maybe_find_pandoc(
|
|||
};
|
||||
|
||||
let pandoc = do vec::find(possible_pandocs) |pandoc| {
|
||||
let output = program_output(*pandoc, ~[~"--version"]);
|
||||
let output = program_output(*pandoc, [~"--version"]);
|
||||
debug!("testing pandoc cmd %s: %?", *pandoc, output);
|
||||
output.status == 0
|
||||
};
|
||||
|
|
|
@ -104,7 +104,7 @@ fn first_sentence(s: ~str) -> Option<~str> {
|
|||
let paras = paragraphs(s);
|
||||
if !paras.is_empty() {
|
||||
let first_para = paras.head();
|
||||
Some(str::replace(first_sentence_(*first_para), ~"\n", ~" "))
|
||||
Some(str::replace(first_sentence_(*first_para), "\n", " "))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ fn first_sentence_(s: &str) -> ~str {
|
|||
str::to_owned(str::slice(s, 0, idx - 1))
|
||||
}
|
||||
_ => {
|
||||
if str::ends_with(s, ~".") {
|
||||
if str::ends_with(s, ".") {
|
||||
str::to_owned(s)
|
||||
} else {
|
||||
str::to_owned(s)
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn mk_pass() -> Pass {
|
|||
}
|
||||
|
||||
fn escape(s: &str) -> ~str {
|
||||
str::replace(s, ~"\\", ~"\\\\")
|
||||
str::replace(s, "\\", "\\\\")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -124,24 +124,24 @@ pub fn pandoc_header_id(header: &str) -> ~str {
|
|||
return header;
|
||||
|
||||
fn remove_formatting(s: &str) -> ~str {
|
||||
str::replace(s, ~"`", ~"")
|
||||
str::replace(s, "`", "")
|
||||
}
|
||||
fn remove_punctuation(s: &str) -> ~str {
|
||||
let s = str::replace(s, ~"<", ~"");
|
||||
let s = str::replace(s, ~">", ~"");
|
||||
let s = str::replace(s, ~"[", ~"");
|
||||
let s = str::replace(s, ~"]", ~"");
|
||||
let s = str::replace(s, ~"(", ~"");
|
||||
let s = str::replace(s, ~")", ~"");
|
||||
let s = str::replace(s, ~"@~", ~"");
|
||||
let s = str::replace(s, ~"~", ~"");
|
||||
let s = str::replace(s, ~"/", ~"");
|
||||
let s = str::replace(s, ~":", ~"");
|
||||
let s = str::replace(s, ~"&", ~"");
|
||||
let s = str::replace(s, ~"^", ~"");
|
||||
let s = str::replace(s, ~",", ~"");
|
||||
let s = str::replace(s, ~"'", ~"");
|
||||
let s = str::replace(s, ~"+", ~"");
|
||||
let s = str::replace(s, "<", "");
|
||||
let s = str::replace(s, ">", "");
|
||||
let s = str::replace(s, "[", "");
|
||||
let s = str::replace(s, "]", "");
|
||||
let s = str::replace(s, "(", "");
|
||||
let s = str::replace(s, ")", "");
|
||||
let s = str::replace(s, "@~", "");
|
||||
let s = str::replace(s, "~", "");
|
||||
let s = str::replace(s, "/", "");
|
||||
let s = str::replace(s, ":", "");
|
||||
let s = str::replace(s, "&", "");
|
||||
let s = str::replace(s, "^", "");
|
||||
let s = str::replace(s, ",", "");
|
||||
let s = str::replace(s, "'", "");
|
||||
let s = str::replace(s, "+", "");
|
||||
return s;
|
||||
}
|
||||
fn replace_with_hyphens(s: &str) -> ~str {
|
||||
|
@ -149,8 +149,8 @@ pub fn pandoc_header_id(header: &str) -> ~str {
|
|||
// XXX: Hacky implementation here that only covers
|
||||
// one or two spaces.
|
||||
let s = str::trim(s);
|
||||
let s = str::replace(s, ~" ", ~"-");
|
||||
let s = str::replace(s, ~" ", ~"-");
|
||||
let s = str::replace(s, " ", "-");
|
||||
let s = str::replace(s, " ", "-");
|
||||
return s;
|
||||
}
|
||||
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
|
||||
|
|
|
@ -110,7 +110,7 @@ fn make_title(page: doc::Page) -> ~str {
|
|||
}
|
||||
};
|
||||
let title = markdown_pass::header_text(item);
|
||||
let title = str::replace(title, ~"`", ~"");
|
||||
let title = str::replace(title, "`", "");
|
||||
return title;
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ pub fn header_kind(doc: doc::ItemTag) -> ~str {
|
|||
}
|
||||
|
||||
pub fn header_name(doc: doc::ItemTag) -> ~str {
|
||||
let fullpath = str::connect(doc.path() + ~[doc.name()], ~"::");
|
||||
let fullpath = str::connect(doc.path() + ~[doc.name()], "::");
|
||||
match &doc {
|
||||
&doc::ModTag(_) if doc.id() != syntax::ast::crate_node_id => {
|
||||
fullpath
|
||||
|
@ -471,7 +471,7 @@ fn write_methods(ctxt: &Ctxt, docs: &[doc::MethodDoc]) {
|
|||
}
|
||||
|
||||
fn write_method(ctxt: &Ctxt, doc: doc::MethodDoc) {
|
||||
write_header_(ctxt, H3, header_text_(~"Method", doc.name));
|
||||
write_header_(ctxt, H3, header_text_("Method", doc.name));
|
||||
write_fnlike(
|
||||
ctxt,
|
||||
copy doc.sig,
|
||||
|
|
|
@ -101,7 +101,7 @@ fn pandoc_writer(
|
|||
use core::io::WriterUtil;
|
||||
|
||||
debug!("pandoc cmd: %s", pandoc_cmd);
|
||||
debug!("pandoc args: %s", str::connect(pandoc_args, ~" "));
|
||||
debug!("pandoc args: %s", str::connect(pandoc_args, " "));
|
||||
|
||||
let pipe_in = os::pipe();
|
||||
let pipe_out = os::pipe();
|
||||
|
@ -198,7 +198,7 @@ pub fn make_filename(
|
|||
}
|
||||
}
|
||||
doc::ItemPage(doc) => {
|
||||
str::connect(doc.path() + ~[doc.name()], ~"_")
|
||||
str::connect(doc.path() + ~[doc.name()], "_")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -213,7 +213,7 @@ pub fn make_filename(
|
|||
fn write_file(path: &Path, s: ~str) {
|
||||
use core::io::WriterUtil;
|
||||
|
||||
match io::file_writer(path, ~[io::Create, io::Truncate]) {
|
||||
match io::file_writer(path, [io::Create, io::Truncate]) {
|
||||
result::Ok(writer) => {
|
||||
writer.write_str(s);
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ fn sectionalize(desc: Option<~str>) -> (Option<~str>, ~[doc::Section]) {
|
|||
}
|
||||
|
||||
fn parse_header(line: ~str) -> Option<~str> {
|
||||
if str::starts_with(line, ~"# ") {
|
||||
if str::starts_with(line, "# ") {
|
||||
Some(str::slice(line, 2u, str::len(line)).to_owned())
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -82,7 +82,7 @@ fn unindent(s: &str) -> ~str {
|
|||
str::slice(*line, min_indent, str::len(*line)).to_owned()
|
||||
}
|
||||
};
|
||||
str::connect(unindented, ~"\n")
|
||||
str::connect(unindented, "\n")
|
||||
} else {
|
||||
s.to_str()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue