From d543354d6c56e8962b0c03397d43df3f16b07d03 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 21 May 2013 22:55:07 +0900 Subject: [PATCH 1/3] Remove unnecessary allocations flagged by lint from rustdoc --- src/librustdoc/attr_parser.rs | 6 ++--- src/librustdoc/config.rs | 8 +++--- src/librustdoc/desc_to_brief_pass.rs | 4 +-- src/librustdoc/escape_pass.rs | 2 +- src/librustdoc/markdown_index_pass.rs | 36 +++++++++++++-------------- src/librustdoc/markdown_pass.rs | 6 ++--- src/librustdoc/markdown_writer.rs | 6 ++--- src/librustdoc/sectionalize_pass.rs | 2 +- src/librustdoc/unindent_pass.rs | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/librustdoc/attr_parser.rs b/src/librustdoc/attr_parser.rs index 433809b9db2..ec31795337b 100644 --- a/src/librustdoc/attr_parser.rs +++ b/src/librustdoc/attr_parser.rs @@ -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 diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 0644b57a0f4..7464b708045 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -70,12 +70,12 @@ fn opts() -> ~[(getopts::Opt, ~str)] { pub fn usage() { use core::io::println; - println(~"Usage: rustdoc [options] \n"); - println(~"Options:\n"); + println("Usage: rustdoc [options] \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 }; diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index c25764ab060..c61b38743fd 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -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) diff --git a/src/librustdoc/escape_pass.rs b/src/librustdoc/escape_pass.rs index 11e9b71afdf..045e916b110 100644 --- a/src/librustdoc/escape_pass.rs +++ b/src/librustdoc/escape_pass.rs @@ -20,7 +20,7 @@ pub fn mk_pass() -> Pass { } fn escape(s: &str) -> ~str { - str::replace(s, ~"\\", ~"\\\\") + str::replace(s, "\\", "\\\\") } #[test] diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs index 2c34f3543b7..c7329c4a54b 100644 --- a/src/librustdoc/markdown_index_pass.rs +++ b/src/librustdoc/markdown_index_pass.rs @@ -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 @@ fn replace_with_hyphens(s: &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 diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index 1eac09ea205..4f4bb4194a8 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -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, diff --git a/src/librustdoc/markdown_writer.rs b/src/librustdoc/markdown_writer.rs index 94372127a22..671364f4dbb 100644 --- a/src/librustdoc/markdown_writer.rs +++ b/src/librustdoc/markdown_writer.rs @@ -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); } diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index 8c3704d55c7..afd29ab7248 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -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 diff --git a/src/librustdoc/unindent_pass.rs b/src/librustdoc/unindent_pass.rs index 826012a2447..1e3e4acce05 100644 --- a/src/librustdoc/unindent_pass.rs +++ b/src/librustdoc/unindent_pass.rs @@ -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() } From d4724c1a178252c240c9ad012fc3cba93f18babc Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 21 May 2013 23:00:34 +0900 Subject: [PATCH 2/3] Remove unnecessary allocations flagged by lint from rustpkg --- src/librustpkg/rustpkg.rc | 26 +++++++++++++------------- src/librustpkg/usage.rs | 20 ++++++++++---------- src/librustpkg/util.rs | 12 ++++++------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc index c1aaa428715..94fdcddfbb5 100644 --- a/src/librustpkg/rustpkg.rc +++ b/src/librustpkg/rustpkg.rc @@ -126,14 +126,14 @@ impl<'self> PkgScript<'self> { &exe, @copy os::args()[0], driver::cu_everything); debug!("Running program: %s %s %s", exe.to_str(), root.to_str(), what); - let status = run::run_program(exe.to_str(), ~[root.to_str(), what]); + let status = run::run_program(exe.to_str(), [root.to_str(), what]); if status != 0 { return (~[], status); } else { debug!("Running program (configs): %s %s %s", - exe.to_str(), root.to_str(), ~"configs"); - let output = run::program_output(exe.to_str(), ~[root.to_str(), ~"configs"]); + exe.to_str(), root.to_str(), "configs"); + let output = run::program_output(exe.to_str(), [root.to_str(), ~"configs"]); // Run the configs() function to get the configs let mut cfgs = ~[]; for str::each_word(output.out) |w| { @@ -360,9 +360,9 @@ pub fn main() { io::println("WARNING: The Rust package manager is experimental and may be unstable"); let args = os::args(); - let opts = ~[getopts::optflag(~"h"), getopts::optflag(~"help"), - getopts::optflag(~"j"), getopts::optflag(~"json"), - getopts::optmulti(~"c"), getopts::optmulti(~"cfg")]; + let opts = ~[getopts::optflag("h"), getopts::optflag("help"), + getopts::optflag("j"), getopts::optflag("json"), + getopts::optmulti("c"), getopts::optmulti("cfg")]; let matches = &match getopts::getopts(args, opts) { result::Ok(m) => m, result::Err(f) => { @@ -371,10 +371,10 @@ pub fn main() { return; } }; - let help = getopts::opt_present(matches, ~"h") || - getopts::opt_present(matches, ~"help"); - let json = getopts::opt_present(matches, ~"j") || - getopts::opt_present(matches, ~"json"); + let help = getopts::opt_present(matches, "h") || + getopts::opt_present(matches, "help"); + let json = getopts::opt_present(matches, "j") || + getopts::opt_present(matches, "json"); let mut args = copy matches.free; args.shift(); @@ -428,7 +428,7 @@ pub impl Crate { fn flag(&self, flag: ~str) -> Crate { Crate { - flags: vec::append(copy self.flags, ~[flag]), + flags: vec::append(copy self.flags, [flag]), .. copy *self } } @@ -442,7 +442,7 @@ pub impl Crate { fn cfg(&self, cfg: ~str) -> Crate { Crate { - cfgs: vec::append(copy self.cfgs, ~[cfg]), + cfgs: vec::append(copy self.cfgs, [cfg]), .. copy *self } } @@ -546,7 +546,7 @@ impl PkgSrc { let url = fmt!("https://%s", self.id.remote_path.to_str()); util::note(fmt!("git clone %s %s", url, local.to_str())); - if run::program_output(~"git", ~[~"clone", copy url, local.to_str()]).status != 0 { + if run::program_output("git", [~"clone", copy url, local.to_str()]).status != 0 { util::note(fmt!("fetching %s failed: can't clone repository", url)); return false; } diff --git a/src/librustpkg/usage.rs b/src/librustpkg/usage.rs index cfda56f777a..90c87210faa 100644 --- a/src/librustpkg/usage.rs +++ b/src/librustpkg/usage.rs @@ -11,7 +11,7 @@ use core::io; pub fn general() { - io::println(~"Usage: rustpkg [options] [args..] + io::println("Usage: rustpkg [options] [args..] Where is one of: build, clean, do, info, install, prefer, test, uninstall, unprefer @@ -23,7 +23,7 @@ pub fn general() { } pub fn build() { - io::println(~"rustpkg [options..] build + io::println("rustpkg [options..] build Build all targets described in the package script in the current directory. @@ -33,21 +33,21 @@ pub fn build() { } pub fn clean() { - io::println(~"rustpkg clean + io::println("rustpkg clean Remove all build files in the work cache for the package in the current directory."); } pub fn do_cmd() { - io::println(~"rustpkg do + io::println("rustpkg do Runs a command in the package script. You can listen to a command by tagging a function with the attribute `#[pkg_do(cmd)]`."); } pub fn info() { - io::println(~"rustpkg [options..] info + io::println("rustpkg [options..] info Probe the package script in the current directory for information. @@ -56,7 +56,7 @@ pub fn info() { } pub fn install() { - io::println(~"rustpkg [options..] install [url] [target] + io::println("rustpkg [options..] install [url] [target] Install a package from a URL by Git or cURL (FTP, HTTP, etc.). If target is provided, Git will checkout the branch or tag before @@ -76,14 +76,14 @@ pub fn install() { } pub fn uninstall() { - io::println(~"rustpkg uninstall [@version] + io::println("rustpkg uninstall [@version] Remove a package by id or name and optionally version. If the package(s) is/are depended on by another package then they cannot be removed."); } pub fn prefer() { - io::println(~"rustpkg [options..] prefer [@version] + io::println("rustpkg [options..] prefer [@version] By default all binaries are given a unique name so that multiple versions can coexist. The prefer command will symlink the uniquely named binary to @@ -101,7 +101,7 @@ pub fn prefer() { } pub fn unprefer() { - io::println(~"rustpkg [options..] unprefer [@version] + io::println("rustpkg [options..] unprefer [@version] Remove all symlinks from the store to the binary directory for a package name and optionally version. If version is not supplied, the latest version @@ -110,7 +110,7 @@ pub fn unprefer() { } pub fn test() { - io::println(~"rustpkg [options..] test + io::println("rustpkg [options..] test Build all targets described in the package script in the current directory with the test flag. The test bootstraps will be run afterwards and the output diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 0ae9539fece..2ee16c67ddd 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -208,7 +208,7 @@ fn fold_item(ctx: @mut ReadyCtx, fold: @fold::ast_fold) -> Option<@ast::item> { ctx.path.push(item.ident); - let attrs = attr::find_attrs_by_name(item.attrs, ~"pkg_do"); + let attrs = attr::find_attrs_by_name(item.attrs, "pkg_do"); if attrs.len() > 0 { let mut cmds = ~[]; @@ -281,7 +281,7 @@ pub fn note(msg: ~str) { if term::color_supported() { term::fg(out, term::color_green); - out.write_str(~"note: "); + out.write_str("note: "); term::reset(out); out.write_line(msg); } else { @@ -294,7 +294,7 @@ pub fn warn(msg: ~str) { if term::color_supported() { term::fg(out, term::color_yellow); - out.write_str(~"warning: "); + out.write_str("warning: "); term::reset(out); out.write_line(msg); } else { @@ -307,7 +307,7 @@ pub fn error(msg: ~str) { if term::color_supported() { term::fg(out, term::color_red); - out.write_str(~"error: "); + out.write_str("error: "); term::reset(out); out.write_line(msg); } else { @@ -353,8 +353,8 @@ pub fn compile_input(sysroot: Option<@Path>, debug!("compiling %s into %s", in_file.to_str(), out_file.to_str()); - debug!("flags: %s", str::connect(flags, ~" ")); - debug!("cfgs: %s", str::connect(cfgs, ~" ")); + debug!("flags: %s", str::connect(flags, " ")); + debug!("cfgs: %s", str::connect(cfgs, " ")); debug!("compile_input's sysroot = %?", sysroot); let crate_type = match what { From 70222b7e86da5a813f9bcf60d884389fc8b04ef7 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 21 May 2013 23:05:45 +0900 Subject: [PATCH 3/3] Remove unnecessary allocations flagged by lint from fuzzer --- src/libfuzzer/fuzzer.rc | 46 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 6662af3b596..468f50a0cc1 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -38,7 +38,7 @@ pub enum test_mode { tm_converge, tm_run, } pub struct Context { mode: test_mode } // + rng pub fn write_file(filename: &Path, content: &str) { - result::get(&io::file_writer(filename, ~[io::Create, io::Truncate])) + result::get(&io::file_writer(filename, [io::Create, io::Truncate])) .write_str(content); } @@ -47,12 +47,12 @@ pub fn contains(haystack: &str, needle: &str) -> bool { } pub fn find_rust_files(files: &mut ~[Path], path: &Path) { - if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") { + if path.filetype() == Some(~".rs") && !contains(path.to_str(), "utf8") { // ignoring "utf8" tests because something is broken files.push(path.clone()); } else if os::path_is_dir(path) - && !contains(path.to_str(), ~"compile-fail") - && !contains(path.to_str(), ~"build") { + && !contains(path.to_str(), "compile-fail") + && !contains(path.to_str(), "build") { for os::list_dir_path(path).each |p| { find_rust_files(&mut *files, *p); } @@ -406,34 +406,34 @@ pub fn check_whole_compiler(code: &str, pub fn removeIfExists(filename: &Path) { // So sketchy! - assert!(!contains(filename.to_str(), ~" ")); - run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]); + assert!(!contains(filename.to_str(), " ")); + run::program_output("bash", [~"-c", ~"rm " + filename.to_str()]); } pub fn removeDirIfExists(filename: &Path) { // So sketchy! - assert!(!contains(filename.to_str(), ~" ")); - run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]); + assert!(!contains(filename.to_str(), " ")); + run::program_output("bash", [~"-c", ~"rm -r " + filename.to_str()]); } pub fn check_running(exe_filename: &Path) -> happiness { let p = run::program_output( - ~"/Users/jruderman/scripts/timed_run_rust_program.py", - ~[exe_filename.to_str()]); + "/Users/jruderman/scripts/timed_run_rust_program.py", + [exe_filename.to_str()]); let comb = p.out + ~"\n" + p.err; if str::len(comb) > 1u { error!("comb comb comb: %?", comb); } - if contains(comb, ~"Assertion failed:") { + if contains(comb, "Assertion failed:") { failed(~"C++ assertion failure") - } else if contains(comb, ~"leaked memory in rust main loop") { + } else if contains(comb, "leaked memory in rust main loop") { // might also use exit code 134 //failed("Leaked") known_bug(~"https://github.com/mozilla/rust/issues/910") - } else if contains(comb, ~"src/rt/") { + } else if contains(comb, "src/rt/") { failed(~"Mentioned src/rt/") - } else if contains(comb, ~"malloc") { + } else if contains(comb, "malloc") { failed(~"Mentioned malloc") } else { match p.status { @@ -457,26 +457,26 @@ pub fn check_running(exe_filename: &Path) -> happiness { pub fn check_compiling(filename: &Path) -> happiness { let p = run::program_output( - ~"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\ + "/Users/jruderman/code/rust/build/x86_64-apple-darwin/\ stage1/bin/rustc", - ~[filename.to_str()]); + [filename.to_str()]); //error!("Status: %d", p.status); if p.status == 0 { passed } else if p.err != ~"" { - if contains(p.err, ~"error:") { + if contains(p.err, "error:") { cleanly_rejected(~"rejected with span_error") } else { error!("Stderr: %?", p.err); failed(~"Unfamiliar error message") } - } else if contains(p.out, ~"Assertion") && contains(p.out, ~"failed") { + } else if contains(p.out, "Assertion") && contains(p.out, "failed") { error!("Stdout: %?", p.out); failed(~"Looks like an llvm assertion failure") - } else if contains(p.out, ~"internal compiler error unimplemented") { + } else if contains(p.out, "internal compiler error unimplemented") { known_bug(~"Something unimplemented") - } else if contains(p.out, ~"internal compiler error") { + } else if contains(p.out, "internal compiler error") { error!("Stdout: %?", p.out); failed(~"internal compiler error") @@ -603,8 +603,8 @@ pub fn check_roundtrip_convergence(code: @~str, maxIters: uint) { error!("Did not converge after %u iterations!", i); write_file(&Path("round-trip-a.rs"), *oldv); write_file(&Path("round-trip-b.rs"), *newv); - run::run_program(~"diff", - ~[~"-w", ~"-u", ~"round-trip-a.rs", + run::run_program("diff", + [~"-w", ~"-u", ~"round-trip-a.rs", ~"round-trip-b.rs"]); fail!("Mismatch"); } @@ -635,7 +635,7 @@ pub fn check_variants(files: &[Path], cx: Context) { } let s = @result::get(&io::read_whole_file_str(file)); - if contains(*s, ~"#") { + if contains(*s, "#") { loop; // Macros are confusing } if cx.mode == tm_converge && content_might_not_converge(*s) {