Skip to content

Commit 82fa001

Browse files
committed
Remove all unnecessary allocations (as flagged by lint)
1 parent 074799b commit 82fa001

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1022
-1027
lines changed

src/libcore/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn self_exe_path() -> Option<Path> {
509509
* Otherwise, homedir returns option::none.
510510
*/
511511
pub fn homedir() -> Option<Path> {
512-
return match getenv(~"HOME") {
512+
return match getenv("HOME") {
513513
Some(ref p) => if !str::is_empty(*p) {
514514
Some(Path(*p))
515515
} else {

src/libcore/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ pub fn to_utf16(s: &str) -> ~[u16] {
18081808
ch -= 0x1_0000_u32;
18091809
let w1 = 0xD800_u16 | ((ch >> 10) as u16);
18101810
let w2 = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16);
1811-
u.push_all(~[w1, w2])
1811+
u.push_all([w1, w2])
18121812
}
18131813
}
18141814
u

src/libcore/unstable/extfmt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub mod ct {
178178
i += 1;
179179

180180
if i >= lim {
181-
err(~"unterminated conversion at end of string");
181+
err("unterminated conversion at end of string");
182182
} else if s[i] == '%' as u8 {
183183
push_slice(&mut pieces, s, h, i);
184184
i += 1;
@@ -309,7 +309,7 @@ pub mod ct {
309309

310310
pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
311311
Parsed<Ty> {
312-
if i >= lim { err(~"missing type in conversion"); }
312+
if i >= lim { err("missing type in conversion"); }
313313

314314
// FIXME (#2249): Do we really want two signed types here?
315315
// How important is it to be printf compatible?

src/librustc/back/link.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ pub mod write {
387387
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
388388
}
389389
&None => {
390-
sess.fatal(~"need Android NDK path for building \
391-
(--android-cross-path)")
390+
sess.fatal("need Android NDK path for building \
391+
(--android-cross-path)")
392392
}
393393
};
394394
let mut cc_args = ~[];
@@ -403,7 +403,7 @@ pub mod write {
403403
sess.err(fmt!("building with `%s` failed with code %d",
404404
cc_prog, prog.status));
405405
sess.note(fmt!("%s arguments: %s",
406-
cc_prog, str::connect(cc_args, ~" ")));
406+
cc_prog, str::connect(cc_args, " ")));
407407
sess.note(prog.err + prog.out);
408408
sess.abort_if_errors();
409409
}
@@ -566,7 +566,7 @@ pub fn build_link_meta(sess: Session,
566566
|| fmt!("output file name `%s` doesn't\
567567
appear to have a stem",
568568
output.to_str())).to_managed();
569-
warn_missing(sess, ~"name", name);
569+
warn_missing(sess, "name", name);
570570
name
571571
}
572572
};
@@ -577,7 +577,7 @@ pub fn build_link_meta(sess: Session,
577577
Some(v) => v,
578578
None => {
579579
let vers = @"0.0";
580-
warn_missing(sess, ~"vers", vers);
580+
warn_missing(sess, "vers", vers);
581581
vers
582582
}
583583
};
@@ -618,9 +618,9 @@ pub fn symbol_hash(tcx: ty::ctxt,
618618

619619
symbol_hasher.reset();
620620
write_string(symbol_hasher, link_meta.name);
621-
write_string(symbol_hasher, ~"-");
621+
write_string(symbol_hasher, "-");
622622
write_string(symbol_hasher, link_meta.extras_hash);
623-
write_string(symbol_hasher, ~"-");
623+
write_string(symbol_hasher, "-");
624624
write_string(symbol_hasher, encoder::encoded_ty(tcx, t));
625625
let mut hash = truncated_hash_result(symbol_hasher);
626626
// Prefix with _ so that it never blends into adjacent digits
@@ -770,8 +770,8 @@ pub fn link_binary(sess: Session,
770770
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
771771
}
772772
&None => {
773-
sess.fatal(~"need Android NDK path for linking \
774-
(--android-cross-path)")
773+
sess.fatal("need Android NDK path for linking \
774+
(--android-cross-path)")
775775
}
776776
}
777777
} else if sess.targ_cfg.os == session::os_win32 {
@@ -798,21 +798,21 @@ pub fn link_binary(sess: Session,
798798

799799
debug!("output: %s", output.to_str());
800800
let cc_args = link_args(sess, obj_filename, out_filename, lm);
801-
debug!("%s link args: %s", cc_prog, str::connect(cc_args, ~" "));
801+
debug!("%s link args: %s", cc_prog, str::connect(cc_args, " "));
802802
// We run 'cc' here
803803
let prog = run::program_output(cc_prog, cc_args);
804804
if 0 != prog.status {
805805
sess.err(fmt!("linking with `%s` failed with code %d",
806806
cc_prog, prog.status));
807807
sess.note(fmt!("%s arguments: %s",
808-
cc_prog, str::connect(cc_args, ~" ")));
808+
cc_prog, str::connect(cc_args, " ")));
809809
sess.note(prog.err + prog.out);
810810
sess.abort_if_errors();
811811
}
812812

813813
// Clean up on Darwin
814814
if sess.targ_cfg.os == session::os_macos {
815-
run::run_program(~"dsymutil", ~[output.to_str()]);
815+
run::run_program("dsymutil", [output.to_str()]);
816816
}
817817

818818
// Remove the temporary object file if we aren't saving temps
@@ -920,27 +920,26 @@ pub fn link_args(sess: Session,
920920
// On linux librt and libdl are an indirect dependencies via rustrt,
921921
// and binutils 2.22+ won't add them automatically
922922
if sess.targ_cfg.os == session::os_linux {
923-
args.push_all(~[~"-lrt", ~"-ldl"]);
923+
args.push_all([~"-lrt", ~"-ldl"]);
924924

925925
// LLVM implements the `frem` instruction as a call to `fmod`,
926926
// which lives in libm. Similar to above, on some linuxes we
927927
// have to be explicit about linking to it. See #2510
928928
args.push(~"-lm");
929929
}
930930
else if sess.targ_cfg.os == session::os_android {
931-
args.push_all(~[~"-ldl", ~"-llog", ~"-lsupc++",
932-
~"-lgnustl_shared"]);
931+
args.push_all([~"-ldl", ~"-llog", ~"-lsupc++", ~"-lgnustl_shared"]);
933932
args.push(~"-lm");
934933
}
935934

936935
if sess.targ_cfg.os == session::os_freebsd {
937-
args.push_all(~[~"-pthread", ~"-lrt",
938-
~"-L/usr/local/lib", ~"-lexecinfo",
939-
~"-L/usr/local/lib/gcc46",
940-
~"-L/usr/local/lib/gcc44", ~"-lstdc++",
941-
~"-Wl,-z,origin",
942-
~"-Wl,-rpath,/usr/local/lib/gcc46",
943-
~"-Wl,-rpath,/usr/local/lib/gcc44"]);
936+
args.push_all([~"-pthread", ~"-lrt",
937+
~"-L/usr/local/lib", ~"-lexecinfo",
938+
~"-L/usr/local/lib/gcc46",
939+
~"-L/usr/local/lib/gcc44", ~"-lstdc++",
940+
~"-Wl,-z,origin",
941+
~"-Wl,-rpath,/usr/local/lib/gcc46",
942+
~"-Wl,-rpath,/usr/local/lib/gcc44"]);
944943
}
945944

946945
// OS X 10.6 introduced 'compact unwind info', which is produced by the

src/librustc/back/rpath.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ fn get_rpaths(os: session::os,
8686
}
8787
}
8888

89-
log_rpaths(~"relative", rel_rpaths);
90-
log_rpaths(~"absolute", abs_rpaths);
91-
log_rpaths(~"fallback", fallback_rpaths);
89+
log_rpaths("relative", rel_rpaths);
90+
log_rpaths("absolute", abs_rpaths);
91+
log_rpaths("fallback", fallback_rpaths);
9292

9393
let mut rpaths = rel_rpaths;
9494
rpaths.push_all(abs_rpaths);

src/librustc/driver/driver.rs

+64-45
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
376376
match node {
377377
pprust::node_expr(s, expr) => {
378378
pp::space(s.s);
379-
pp::word(s.s, ~"as");
379+
pp::word(s.s, "as");
380380
pp::space(s.s);
381381
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
382382
pprust::pclose(s);
@@ -442,33 +442,33 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
442442
}
443443
444444
pub fn get_os(triple: &str) -> Option<session::os> {
445-
if str::contains(triple, ~"win32") ||
446-
str::contains(triple, ~"mingw32") {
445+
if str::contains(triple, "win32") ||
446+
str::contains(triple, "mingw32") {
447447
Some(session::os_win32)
448-
} else if str::contains(triple, ~"darwin") {
448+
} else if str::contains(triple, "darwin") {
449449
Some(session::os_macos)
450-
} else if str::contains(triple, ~"android") {
450+
} else if str::contains(triple, "android") {
451451
Some(session::os_android)
452-
} else if str::contains(triple, ~"linux") {
452+
} else if str::contains(triple, "linux") {
453453
Some(session::os_linux)
454-
} else if str::contains(triple, ~"freebsd") {
454+
} else if str::contains(triple, "freebsd") {
455455
Some(session::os_freebsd)
456456
} else { None }
457457
}
458458

459459
pub fn get_arch(triple: &str) -> Option<abi::Architecture> {
460-
if str::contains(triple, ~"i386") ||
461-
str::contains(triple, ~"i486") ||
462-
str::contains(triple, ~"i586") ||
463-
str::contains(triple, ~"i686") ||
464-
str::contains(triple, ~"i786") {
460+
if str::contains(triple, "i386") ||
461+
str::contains(triple, "i486") ||
462+
str::contains(triple, "i586") ||
463+
str::contains(triple, "i686") ||
464+
str::contains(triple, "i786") {
465465
Some(abi::X86)
466-
} else if str::contains(triple, ~"x86_64") {
466+
} else if str::contains(triple, "x86_64") {
467467
Some(abi::X86_64)
468-
} else if str::contains(triple, ~"arm") ||
469-
str::contains(triple, ~"xscale") {
468+
} else if str::contains(triple, "arm") ||
469+
str::contains(triple, "xscale") {
470470
Some(abi::Arm)
471-
} else if str::contains(triple, ~"mips") {
471+
} else if str::contains(triple, "mips") {
472472
Some(abi::Mips)
473473
} else { None }
474474
}
@@ -508,6 +508,7 @@ pub fn build_target_config(sopts: @session::options,
508508
return target_cfg;
509509
}
510510
511+
#[cfg(stage0)]
511512
pub fn host_triple() -> ~str {
512513
// Get the host triple out of the build environment. This ensures that our
513514
// idea of the host triple is the same as for the set of libraries we've
@@ -525,19 +526,37 @@ pub fn host_triple() -> ~str {
525526
};
526527
}
527528

529+
#[cfg(not(stage0))]
530+
pub fn host_triple() -> ~str {
531+
// Get the host triple out of the build environment. This ensures that our
532+
// idea of the host triple is the same as for the set of libraries we've
533+
// actually built. We can't just take LLVM's host triple because they
534+
// normalize all ix86 architectures to i386.
535+
536+
// FIXME (#2400): Instead of grabbing the host triple we really should
537+
// be grabbing (at compile time) the target triple that this rustc is
538+
// built with and calling that (at runtime) the host triple.
539+
let ht = env!("CFG_BUILD_TRIPLE");
540+
return if ht != "" {
541+
ht.to_owned()
542+
} else {
543+
fail!("rustc built without CFG_BUILD_TRIPLE")
544+
};
545+
}
546+
528547
pub fn build_session_options(binary: @~str,
529548
matches: &getopts::Matches,
530549
demitter: diagnostic::Emitter)
531550
-> @session::options {
532-
let crate_type = if opt_present(matches, ~"lib") {
551+
let crate_type = if opt_present(matches, "lib") {
533552
session::lib_crate
534-
} else if opt_present(matches, ~"bin") {
553+
} else if opt_present(matches, "bin") {
535554
session::bin_crate
536555
} else {
537556
session::unknown_crate
538557
};
539-
let parse_only = opt_present(matches, ~"parse-only");
540-
let no_trans = opt_present(matches, ~"no-trans");
558+
let parse_only = opt_present(matches, "parse-only");
559+
let no_trans = opt_present(matches, "no-trans");
541560

542561
let lint_levels = [lint::allow, lint::warn,
543562
lint::deny, lint::forbid];
@@ -553,7 +572,7 @@ pub fn build_session_options(binary: @~str,
553572
let flags = vec::append(getopts::opt_strs(matches, level_short),
554573
getopts::opt_strs(matches, level_name));
555574
for flags.each |lint_name| {
556-
let lint_name = str::replace(*lint_name, ~"-", ~"_");
575+
let lint_name = str::replace(*lint_name, "-", "_");
557576
match lint_dict.find(&lint_name) {
558577
None => {
559578
early_error(demitter, fmt!("unknown %s flag: %s",
@@ -567,7 +586,7 @@ pub fn build_session_options(binary: @~str,
567586
}
568587

569588
let mut debugging_opts = 0u;
570-
let debug_flags = getopts::opt_strs(matches, ~"Z");
589+
let debug_flags = getopts::opt_strs(matches, "Z");
571590
let debug_map = session::debugging_opts_map();
572591
for debug_flags.each |debug_flag| {
573592
let mut this_bit = 0u;
@@ -589,31 +608,31 @@ pub fn build_session_options(binary: @~str,
589608
let output_type =
590609
if parse_only || no_trans {
591610
link::output_type_none
592-
} else if opt_present(matches, ~"S") &&
593-
opt_present(matches, ~"emit-llvm") {
611+
} else if opt_present(matches, "S") &&
612+
opt_present(matches, "emit-llvm") {
594613
link::output_type_llvm_assembly
595-
} else if opt_present(matches, ~"S") {
614+
} else if opt_present(matches, "S") {
596615
link::output_type_assembly
597-
} else if opt_present(matches, ~"c") {
616+
} else if opt_present(matches, "c") {
598617
link::output_type_object
599-
} else if opt_present(matches, ~"emit-llvm") {
618+
} else if opt_present(matches, "emit-llvm") {
600619
link::output_type_bitcode
601620
} else { link::output_type_exe };
602-
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
621+
let sysroot_opt = getopts::opt_maybe_str(matches, "sysroot");
603622
let sysroot_opt = sysroot_opt.map(|m| @Path(*m));
604-
let target_opt = getopts::opt_maybe_str(matches, ~"target");
605-
let target_feature_opt = getopts::opt_maybe_str(matches, ~"target-feature");
606-
let save_temps = getopts::opt_present(matches, ~"save-temps");
623+
let target_opt = getopts::opt_maybe_str(matches, "target");
624+
let target_feature_opt = getopts::opt_maybe_str(matches, "target-feature");
625+
let save_temps = getopts::opt_present(matches, "save-temps");
607626
let opt_level = {
608627
if (debugging_opts & session::no_opt) != 0 {
609628
No
610-
} else if opt_present(matches, ~"O") {
611-
if opt_present(matches, ~"opt-level") {
629+
} else if opt_present(matches, "O") {
630+
if opt_present(matches, "opt-level") {
612631
early_error(demitter, ~"-O and --opt-level both provided");
613632
}
614633
Default
615-
} else if opt_present(matches, ~"opt-level") {
616-
match getopts::opt_str(matches, ~"opt-level") {
634+
} else if opt_present(matches, "opt-level") {
635+
match getopts::opt_str(matches, "opt-level") {
617636
~"0" => No,
618637
~"1" => Less,
619638
~"2" => Default,
@@ -641,20 +660,20 @@ pub fn build_session_options(binary: @~str,
641660
Some(s) => s
642661
};
643662

644-
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
645-
let linker = getopts::opt_maybe_str(matches, ~"linker");
646-
let linker_args = getopts::opt_strs(matches, ~"link-args").flat_map( |a| {
663+
let addl_lib_search_paths = getopts::opt_strs(matches, "L").map(|s| Path(*s));
664+
let linker = getopts::opt_maybe_str(matches, "linker");
665+
let linker_args = getopts::opt_strs(matches, "link-args").flat_map( |a| {
647666
let mut args = ~[];
648667
for str::each_split_char(*a, ' ') |arg| {
649668
args.push(str::to_owned(arg));
650669
}
651670
args
652671
});
653672

654-
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"), demitter);
655-
let test = opt_present(matches, ~"test");
673+
let cfg = parse_cfgspecs(getopts::opt_strs(matches, "cfg"), demitter);
674+
let test = opt_present(matches, "test");
656675
let android_cross_path = getopts::opt_maybe_str(
657-
matches, ~"android-cross-path");
676+
matches, "android-cross-path");
658677

659678
let sopts = @session::options {
660679
crate_type: crate_type,
@@ -732,9 +751,9 @@ pub fn parse_pretty(sess: Session, name: &str) -> pp_mode {
732751
&"expanded,identified" => ppm_expanded_identified,
733752
&"identified" => ppm_identified,
734753
_ => {
735-
sess.fatal(~"argument to `pretty` must be one of `normal`, \
736-
`expanded`, `typed`, `identified`, \
737-
or `expanded,identified`");
754+
sess.fatal("argument to `pretty` must be one of `normal`, \
755+
`expanded`, `typed`, `identified`, \
756+
or `expanded,identified`");
738757
}
739758
}
740759
}
@@ -875,7 +894,7 @@ pub fn build_output_filenames(input: &input,
875894
}
876895

877896
if *odir != None {
878-
sess.warn(~"ignoring --out-dir flag due to -o flag.");
897+
sess.warn("ignoring --out-dir flag due to -o flag.");
879898
}
880899
}
881900
}

0 commit comments

Comments
 (0)