Skip to content

Commit fc502e2

Browse files
committed
auto merge of #15194 : Sawyer47/rust/to-string-cleanup, r=alexcrichton
This commit removes superfluous to_string calls from various places
2 parents 389fae2 + f8e06c4 commit fc502e2

File tree

26 files changed

+62
-106
lines changed

26 files changed

+62
-106
lines changed

src/compiletest/runtest.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
320320

321321
let config = &mut config;
322322
let DebuggerCommands { commands, check_lines, .. } = parse_debugger_commands(testfile, "gdb");
323-
let mut cmds = commands.connect("\n").to_string();
323+
let mut cmds = commands.connect("\n");
324324

325325
// compile test file (it shoud have 'compile-flags:-g' in the header)
326326
let compiler_run_result = compile_test(config, props, testfile);
@@ -1035,10 +1035,7 @@ fn compose_and_run_compiler(
10351035
make_compile_args(config,
10361036
&aux_props,
10371037
crate_type.append(
1038-
extra_link_args.iter()
1039-
.map(|x| x.to_string())
1040-
.collect::<Vec<_>>()
1041-
.as_slice()),
1038+
extra_link_args.as_slice()),
10421039
|a,b| {
10431040
let f = make_lib_name(a, b, testfile);
10441041
ThisDirectory(f.dir_path())

src/libgetopts/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@
4949
//! }
5050
//!
5151
//! fn main() {
52-
//! let args: Vec<String> = os::args().iter()
53-
//! .map(|x| x.to_string())
54-
//! .collect();
52+
//! let args: Vec<String> = os::args();
5553
//!
5654
//! let program = args.get(0).clone();
5755
//!

src/librustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ pub fn sanitize(s: &str) -> String {
659659
if result.len() > 0u &&
660660
result.as_slice()[0] != '_' as u8 &&
661661
! char::is_XID_start(result.as_slice()[0] as char) {
662-
return format!("_{}", result.as_slice()).to_string();
662+
return format!("_{}", result.as_slice());
663663
}
664664

665665
return result;

src/librustc/driver/config.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
650650
}
651651

652652
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
653-
let target = match matches.opt_str("target") {
654-
Some(supplied_target) => supplied_target.to_string(),
655-
None => driver::host_triple().to_string(),
656-
};
653+
let target = matches.opt_str("target").unwrap_or(
654+
driver::host_triple().to_string());
657655
let opt_level = {
658656
if (debugging_opts & NO_OPT) != 0 {
659657
No
@@ -705,10 +703,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
705703
Path::new(s.as_slice())
706704
}).collect();
707705

708-
let cfg = parse_cfgspecs(matches.opt_strs("cfg")
709-
.move_iter()
710-
.map(|x| x.to_string())
711-
.collect());
706+
let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
712707
let test = matches.opt_present("test");
713708
let write_dependency_info = (matches.opt_present("dep-info"),
714709
matches.opt_str("dep-info")

src/librustc/driver/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
595595
}
596596
pprust::NodeBlock(blk) => {
597597
try!(pp::space(&mut s.s));
598-
s.synth_comment((format!("block {}", blk.id)).to_string())
598+
s.synth_comment(format!("block {}", blk.id))
599599
}
600600
pprust::NodeExpr(expr) => {
601601
try!(pp::space(&mut s.s));
@@ -604,7 +604,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
604604
}
605605
pprust::NodePat(pat) => {
606606
try!(pp::space(&mut s.s));
607-
s.synth_comment((format!("pat {}", pat.id)).to_string())
607+
s.synth_comment(format!("pat {}", pat.id))
608608
}
609609
}
610610
}
@@ -752,7 +752,7 @@ fn print_flowgraph<W:io::Writer>(analysis: CrateAnalysis,
752752
let cfg = cfg::CFG::new(ty_cx, &*block);
753753
let lcfg = LabelledCFG { ast_map: &ty_cx.map,
754754
cfg: &cfg,
755-
name: format!("block{}", block.id).to_string(), };
755+
name: format!("block{}", block.id), };
756756
debug!("cfg: {:?}", cfg);
757757
let r = dot::render(&lcfg, &mut out);
758758
return expand_err_details(r);

src/librustc/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ mod rustc {
137137
}
138138

139139
pub fn main() {
140-
let args = std::os::args().iter()
141-
.map(|x| x.to_string())
142-
.collect::<Vec<_>>();
140+
let args = std::os::args();
143141
std::os::set_exit_status(driver::main_args(args.as_slice()));
144142
}

src/librustc/lib/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ impl TypeNames {
18941894

18951895
pub fn types_to_str(&self, tys: &[Type]) -> String {
18961896
let strs: Vec<String> = tys.iter().map(|t| self.type_to_str(*t)).collect();
1897-
format!("[{}]", strs.connect(",").to_string())
1897+
format!("[{}]", strs.connect(","))
18981898
}
18991899

19001900
pub fn val_to_str(&self, val: ValueRef) -> String {

src/librustc/metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ impl<'a> PluginMetadataReader<'a> {
441441
};
442442
let macros = decoder::get_exported_macros(library.metadata.as_slice());
443443
let registrar = decoder::get_plugin_registrar_fn(library.metadata.as_slice()).map(|id| {
444-
decoder::get_symbol(library.metadata.as_slice(), id).to_string()
444+
decoder::get_symbol(library.metadata.as_slice(), id)
445445
});
446446
let pc = PluginMetadata {
447447
lib: library.dylib.clone(),
448-
macros: macros.move_iter().map(|x| x.to_string()).collect(),
448+
macros: macros,
449449
registrar_symbol: registrar,
450450
};
451451
if should_link && existing_match(&self.env, &info.crate_id, None).is_none() {

src/librustc/middle/borrowck/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,37 +801,34 @@ impl DataFlowOperator for LoanDataFlowOperator {
801801

802802
impl Repr for Loan {
803803
fn repr(&self, tcx: &ty::ctxt) -> String {
804-
(format!("Loan_{:?}({}, {:?}, {:?}-{:?}, {})",
804+
format!("Loan_{:?}({}, {:?}, {:?}-{:?}, {})",
805805
self.index,
806806
self.loan_path.repr(tcx),
807807
self.kind,
808808
self.gen_scope,
809809
self.kill_scope,
810-
self.restricted_paths.repr(tcx))).to_string()
810+
self.restricted_paths.repr(tcx))
811811
}
812812
}
813813

814814
impl Repr for LoanPath {
815815
fn repr(&self, tcx: &ty::ctxt) -> String {
816816
match self {
817817
&LpVar(id) => {
818-
(format!("$({})", tcx.map.node_to_str(id))).to_string()
818+
format!("$({})", tcx.map.node_to_str(id))
819819
}
820820

821821
&LpUpvar(ty::UpvarId{ var_id, closure_expr_id }) => {
822822
let s = tcx.map.node_to_str(var_id);
823-
let s = format!("$({} captured by id={})", s, closure_expr_id);
824-
s.to_string()
823+
format!("$({} captured by id={})", s, closure_expr_id)
825824
}
826825

827826
&LpExtend(ref lp, _, LpDeref(_)) => {
828-
(format!("{}.*", lp.repr(tcx))).to_string()
827+
format!("{}.*", lp.repr(tcx))
829828
}
830829

831830
&LpExtend(ref lp, _, LpInterior(ref interior)) => {
832-
(format!("{}.{}",
833-
lp.repr(tcx),
834-
interior.repr(tcx))).to_string()
831+
format!("{}.{}", lp.repr(tcx), interior.repr(tcx))
835832
}
836833
}
837834
}

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl Repr for ty::ParamBounds {
629629
for t in self.trait_bounds.iter() {
630630
res.push(t.repr(tcx));
631631
}
632-
res.connect("+").to_string()
632+
res.connect("+")
633633
}
634634
}
635635

0 commit comments

Comments
 (0)