Skip to content

Remove unnecessary allocations flagged by lint #6657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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")

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/desc_to_brief_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/escape_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn mk_pass() -> Pass {
}

fn escape(s: &str) -> ~str {
str::replace(s, ~"\\", ~"\\\\")
str::replace(s, "\\", "\\\\")
}

#[test]
Expand Down
36 changes: 18 additions & 18 deletions src/librustdoc/markdown_index_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,33 @@ 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 {
// Collapse sequences of whitespace to a single dash
// 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
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/markdown_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -198,7 +198,7 @@ pub fn make_filename(
}
}
doc::ItemPage(doc) => {
str::connect(doc.path() + ~[doc.name()], ~"_")
str::connect(doc.path() + ~[doc.name()], "_")
}
}
};
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/sectionalize_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/unindent_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
26 changes: 13 additions & 13 deletions src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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();
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading