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

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
228228
};
229229

230230
// Transform the contents of the header into a hyphenated string
231-
let id = (s.as_slice().words().map(|s| {
231+
let id = s.as_slice().words().map(|s| {
232232
match s.to_ascii_opt() {
233233
Some(s) => s.to_lower().into_str(),
234234
None => s.to_string()
235235
}
236-
}).collect::<Vec<String>>().connect("-")).to_string();
236+
}).collect::<Vec<String>>().connect("-");
237237

238238
// This is a terrible hack working around how hoedown gives us rendered
239239
// html for text rather than the raw text.
@@ -252,7 +252,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
252252

253253
let sec = match opaque.toc_builder {
254254
Some(ref mut builder) => {
255-
builder.push(level as u32, s.to_string(), id.clone())
255+
builder.push(level as u32, s.clone(), id.clone())
256256
}
257257
None => {""}
258258
};

src/librustdoc/html/render.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
370370
search_index.push(IndexItem {
371371
ty: shortty(item),
372372
name: item.name.clone().unwrap(),
373-
path: fqp.slice_to(fqp.len() - 1).connect("::")
374-
.to_string(),
373+
path: fqp.slice_to(fqp.len() - 1).connect("::"),
375374
desc: shorter(item.doc_value()).to_string(),
376375
parent: Some(did),
377376
});

src/librustdoc/lib.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ local_data_key!(pub analysiskey: core::CrateAnalysis)
8585
type Output = (clean::Crate, Vec<plugins::PluginJson> );
8686

8787
pub fn main() {
88-
std::os::set_exit_status(main_args(std::os::args().iter()
89-
.map(|x| x.to_string())
90-
.collect::<Vec<_>>()
91-
.as_slice()));
88+
std::os::set_exit_status(main_args(std::os::args().as_slice()));
9289
}
9390

9491
pub fn opts() -> Vec<getopts::OptGroup> {
@@ -184,17 +181,10 @@ pub fn main_args(args: &[String]) -> int {
184181

185182
match (should_test, markdown_input) {
186183
(true, true) => {
187-
return markdown::test(input,
188-
libs,
189-
test_args.move_iter().collect())
184+
return markdown::test(input, libs, test_args)
190185
}
191186
(true, false) => {
192-
return test::run(input,
193-
cfgs.move_iter()
194-
.map(|x| x.to_string())
195-
.collect(),
196-
libs,
197-
test_args)
187+
return test::run(input, cfgs, libs, test_args)
198188
}
199189
(false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")),
200190
&matches),
@@ -273,10 +263,7 @@ fn acquire_input(input: &str,
273263
fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
274264
let mut default_passes = !matches.opt_present("no-defaults");
275265
let mut passes = matches.opt_strs("passes");
276-
let mut plugins = matches.opt_strs("plugins")
277-
.move_iter()
278-
.map(|x| x.to_string())
279-
.collect::<Vec<_>>();
266+
let mut plugins = matches.opt_strs("plugins");
280267

281268
// First, parse the crate and extract all relevant information.
282269
let libs: Vec<Path> = matches.opt_strs("L")
@@ -289,7 +276,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
289276
let (krate, analysis) = std::task::try(proc() {
290277
let cr = cr;
291278
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
292-
cfgs.move_iter().map(|x| x.to_string()).collect(),
279+
cfgs,
293280
&cr)
294281
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
295282
info!("finished with rustc");

src/librustdoc/markdown.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,10 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int
9393

9494
let (in_header, before_content, after_content) =
9595
match (load_external_files(matches.opt_strs("markdown-in-header")
96-
.move_iter()
97-
.map(|x| x.to_string())
98-
.collect::<Vec<_>>()
9996
.as_slice()),
10097
load_external_files(matches.opt_strs("markdown-before-content")
101-
.move_iter()
102-
.map(|x| x.to_string())
103-
.collect::<Vec<_>>()
10498
.as_slice()),
10599
load_external_files(matches.opt_strs("markdown-after-content")
106-
.move_iter()
107-
.map(|x| x.to_string())
108-
.collect::<Vec<_>>()
109100
.as_slice())) {
110101
(Some(a), Some(b), Some(c)) => (a,b,c),
111102
_ => return 3

src/librustdoc/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ pub fn unindent(s: &str) -> String {
348348
line.slice_from(min_indent).to_string()
349349
}
350350
}).collect::<Vec<_>>().as_slice());
351-
unindented.connect("\n").to_string()
351+
unindented.connect("\n")
352352
} else {
353353
s.to_string()
354354
}

src/libstd/path/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ impl GenericPath for Path {
588588
}
589589
}
590590
}
591-
Some(Path::new(comps.connect("\\").into_string()))
591+
Some(Path::new(comps.connect("\\")))
592592
}
593593
}
594594

src/libsyntax/ast_map.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -680,61 +680,55 @@ fn node_id_to_str(map: &Map, id: NodeId) -> String {
680680
ItemImpl(..) => "impl",
681681
ItemMac(..) => "macro"
682682
};
683-
(format!("{} {} (id={})", item_str, path_str, id)).to_string()
683+
format!("{} {} (id={})", item_str, path_str, id)
684684
}
685685
Some(NodeForeignItem(item)) => {
686686
let path_str = map.path_to_str_with_ident(id, item.ident);
687-
(format!("foreign item {} (id={})", path_str, id)).to_string()
687+
format!("foreign item {} (id={})", path_str, id)
688688
}
689689
Some(NodeMethod(m)) => {
690-
(format!("method {} in {} (id={})",
690+
format!("method {} in {} (id={})",
691691
token::get_ident(m.ident),
692-
map.path_to_str(id), id)).to_string()
692+
map.path_to_str(id), id)
693693
}
694694
Some(NodeTraitMethod(ref tm)) => {
695695
let m = ast_util::trait_method_to_ty_method(&**tm);
696-
(format!("method {} in {} (id={})",
696+
format!("method {} in {} (id={})",
697697
token::get_ident(m.ident),
698-
map.path_to_str(id), id)).to_string()
698+
map.path_to_str(id), id)
699699
}
700700
Some(NodeVariant(ref variant)) => {
701-
(format!("variant {} in {} (id={})",
701+
format!("variant {} in {} (id={})",
702702
token::get_ident(variant.node.name),
703-
map.path_to_str(id), id)).to_string()
703+
map.path_to_str(id), id)
704704
}
705705
Some(NodeExpr(ref expr)) => {
706-
(format!("expr {} (id={})",
707-
pprust::expr_to_str(&**expr), id)).to_string()
706+
format!("expr {} (id={})", pprust::expr_to_str(&**expr), id)
708707
}
709708
Some(NodeStmt(ref stmt)) => {
710-
(format!("stmt {} (id={})",
711-
pprust::stmt_to_str(&**stmt), id)).to_string()
709+
format!("stmt {} (id={})", pprust::stmt_to_str(&**stmt), id)
712710
}
713711
Some(NodeArg(ref pat)) => {
714-
(format!("arg {} (id={})",
715-
pprust::pat_to_str(&**pat), id)).to_string()
712+
format!("arg {} (id={})", pprust::pat_to_str(&**pat), id)
716713
}
717714
Some(NodeLocal(ref pat)) => {
718-
(format!("local {} (id={})",
719-
pprust::pat_to_str(&**pat), id)).to_string()
715+
format!("local {} (id={})", pprust::pat_to_str(&**pat), id)
720716
}
721717
Some(NodePat(ref pat)) => {
722-
(format!("pat {} (id={})", pprust::pat_to_str(&**pat), id)).to_string()
718+
format!("pat {} (id={})", pprust::pat_to_str(&**pat), id)
723719
}
724720
Some(NodeBlock(ref block)) => {
725-
(format!("block {} (id={})",
726-
pprust::block_to_str(&**block), id)).to_string()
721+
format!("block {} (id={})", pprust::block_to_str(&**block), id)
727722
}
728723
Some(NodeStructCtor(_)) => {
729-
(format!("struct_ctor {} (id={})",
730-
map.path_to_str(id), id)).to_string()
724+
format!("struct_ctor {} (id={})", map.path_to_str(id), id)
731725
}
732726
Some(NodeLifetime(ref l)) => {
733-
(format!("lifetime {} (id={})",
734-
pprust::lifetime_to_str(&**l), id)).to_string()
727+
format!("lifetime {} (id={})",
728+
pprust::lifetime_to_str(&**l), id)
735729
}
736730
None => {
737-
(format!("unknown node (id={})", id)).to_string()
731+
format!("unknown node (id={})", id)
738732
}
739733
}
740734
}

0 commit comments

Comments
 (0)