Skip to content

Remove unnecessary to_string calls #15194

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

Merged
merged 1 commit into from
Jun 26, 2014
Merged
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
7 changes: 2 additions & 5 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {

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

// compile test file (it shoud have 'compile-flags:-g' in the header)
let compiler_run_result = compile_test(config, props, testfile);
Expand Down Expand Up @@ -1035,10 +1035,7 @@ fn compose_and_run_compiler(
make_compile_args(config,
&aux_props,
crate_type.append(
extra_link_args.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice()),
extra_link_args.as_slice()),
|a,b| {
let f = make_lib_name(a, b, testfile);
ThisDirectory(f.dir_path())
Expand Down
4 changes: 1 addition & 3 deletions src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
//! }
//!
//! fn main() {
//! let args: Vec<String> = os::args().iter()
//! .map(|x| x.to_string())
//! .collect();
//! let args: Vec<String> = os::args();
//!
//! let program = args.get(0).clone();
//!
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ pub fn sanitize(s: &str) -> String {
if result.len() > 0u &&
result.as_slice()[0] != '_' as u8 &&
! char::is_XID_start(result.as_slice()[0] as char) {
return format!("_{}", result.as_slice()).to_string();
return format!("_{}", result.as_slice());
}

return result;
Expand Down
11 changes: 3 additions & 8 deletions src/librustc/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
}

let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
let target = match matches.opt_str("target") {
Some(supplied_target) => supplied_target.to_string(),
None => driver::host_triple().to_string(),
};
let target = matches.opt_str("target").unwrap_or(
driver::host_triple().to_string());
let opt_level = {
if (debugging_opts & NO_OPT) != 0 {
No
Expand Down Expand Up @@ -705,10 +703,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
Path::new(s.as_slice())
}).collect();

let cfg = parse_cfgspecs(matches.opt_strs("cfg")
.move_iter()
.map(|x| x.to_string())
.collect());
let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
let test = matches.opt_present("test");
let write_dependency_info = (matches.opt_present("dep-info"),
matches.opt_str("dep-info")
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
}
pprust::NodeBlock(blk) => {
try!(pp::space(&mut s.s));
s.synth_comment((format!("block {}", blk.id)).to_string())
s.synth_comment(format!("block {}", blk.id))
}
pprust::NodeExpr(expr) => {
try!(pp::space(&mut s.s));
Expand All @@ -604,7 +604,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
}
pprust::NodePat(pat) => {
try!(pp::space(&mut s.s));
s.synth_comment((format!("pat {}", pat.id)).to_string())
s.synth_comment(format!("pat {}", pat.id))
}
}
}
Expand Down Expand Up @@ -752,7 +752,7 @@ fn print_flowgraph<W:io::Writer>(analysis: CrateAnalysis,
let cfg = cfg::CFG::new(ty_cx, &*block);
let lcfg = LabelledCFG { ast_map: &ty_cx.map,
cfg: &cfg,
name: format!("block{}", block.id).to_string(), };
name: format!("block{}", block.id), };
debug!("cfg: {:?}", cfg);
let r = dot::render(&lcfg, &mut out);
return expand_err_details(r);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ mod rustc {
}

pub fn main() {
let args = std::os::args().iter()
.map(|x| x.to_string())
.collect::<Vec<_>>();
let args = std::os::args();
std::os::set_exit_status(driver::main_args(args.as_slice()));
}
2 changes: 1 addition & 1 deletion src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ impl TypeNames {

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

pub fn val_to_str(&self, val: ValueRef) -> String {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ impl<'a> PluginMetadataReader<'a> {
};
let macros = decoder::get_exported_macros(library.metadata.as_slice());
let registrar = decoder::get_plugin_registrar_fn(library.metadata.as_slice()).map(|id| {
decoder::get_symbol(library.metadata.as_slice(), id).to_string()
decoder::get_symbol(library.metadata.as_slice(), id)
});
let pc = PluginMetadata {
lib: library.dylib.clone(),
macros: macros.move_iter().map(|x| x.to_string()).collect(),
macros: macros,
registrar_symbol: registrar,
};
if should_link && existing_match(&self.env, &info.crate_id, None).is_none() {
Expand Down
15 changes: 6 additions & 9 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,37 +801,34 @@ impl DataFlowOperator for LoanDataFlowOperator {

impl Repr for Loan {
fn repr(&self, tcx: &ty::ctxt) -> String {
(format!("Loan_{:?}({}, {:?}, {:?}-{:?}, {})",
format!("Loan_{:?}({}, {:?}, {:?}-{:?}, {})",
self.index,
self.loan_path.repr(tcx),
self.kind,
self.gen_scope,
self.kill_scope,
self.restricted_paths.repr(tcx))).to_string()
self.restricted_paths.repr(tcx))
}
}

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

&LpUpvar(ty::UpvarId{ var_id, closure_expr_id }) => {
let s = tcx.map.node_to_str(var_id);
let s = format!("$({} captured by id={})", s, closure_expr_id);
s.to_string()
format!("$({} captured by id={})", s, closure_expr_id)
}

&LpExtend(ref lp, _, LpDeref(_)) => {
(format!("{}.*", lp.repr(tcx))).to_string()
format!("{}.*", lp.repr(tcx))
}

&LpExtend(ref lp, _, LpInterior(ref interior)) => {
(format!("{}.{}",
lp.repr(tcx),
interior.repr(tcx))).to_string()
format!("{}.{}", lp.repr(tcx), interior.repr(tcx))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl Repr for ty::ParamBounds {
for t in self.trait_bounds.iter() {
res.push(t.repr(tcx));
}
res.connect("+").to_string()
res.connect("+")
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
};

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

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

let sec = match opaque.toc_builder {
Some(ref mut builder) => {
builder.push(level as u32, s.to_string(), id.clone())
builder.push(level as u32, s.clone(), id.clone())
}
None => {""}
};
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
search_index.push(IndexItem {
ty: shortty(item),
name: item.name.clone().unwrap(),
path: fqp.slice_to(fqp.len() - 1).connect("::")
.to_string(),
path: fqp.slice_to(fqp.len() - 1).connect("::"),
desc: shorter(item.doc_value()).to_string(),
parent: Some(did),
});
Expand Down
23 changes: 5 additions & 18 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ local_data_key!(pub analysiskey: core::CrateAnalysis)
type Output = (clean::Crate, Vec<plugins::PluginJson> );

pub fn main() {
std::os::set_exit_status(main_args(std::os::args().iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice()));
std::os::set_exit_status(main_args(std::os::args().as_slice()));
}

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

match (should_test, markdown_input) {
(true, true) => {
return markdown::test(input,
libs,
test_args.move_iter().collect())
return markdown::test(input, libs, test_args)
}
(true, false) => {
return test::run(input,
cfgs.move_iter()
.map(|x| x.to_string())
.collect(),
libs,
test_args)
return test::run(input, cfgs, libs, test_args)
}
(false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")),
&matches),
Expand Down Expand Up @@ -273,10 +263,7 @@ fn acquire_input(input: &str,
fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
let mut default_passes = !matches.opt_present("no-defaults");
let mut passes = matches.opt_strs("passes");
let mut plugins = matches.opt_strs("plugins")
.move_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>();
let mut plugins = matches.opt_strs("plugins");

// First, parse the crate and extract all relevant information.
let libs: Vec<Path> = matches.opt_strs("L")
Expand All @@ -289,7 +276,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
let (krate, analysis) = std::task::try(proc() {
let cr = cr;
core::run_core(libs.move_iter().map(|x| x.clone()).collect(),
cfgs.move_iter().map(|x| x.to_string()).collect(),
cfgs,
&cr)
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
info!("finished with rustc");
Expand Down
9 changes: 0 additions & 9 deletions src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,10 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int

let (in_header, before_content, after_content) =
match (load_external_files(matches.opt_strs("markdown-in-header")
.move_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice()),
load_external_files(matches.opt_strs("markdown-before-content")
.move_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice()),
load_external_files(matches.opt_strs("markdown-after-content")
.move_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice())) {
(Some(a), Some(b), Some(c)) => (a,b,c),
_ => return 3
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub fn unindent(s: &str) -> String {
line.slice_from(min_indent).to_string()
}
}).collect::<Vec<_>>().as_slice());
unindented.connect("\n").to_string()
unindented.connect("\n")
} else {
s.to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl GenericPath for Path {
}
}
}
Some(Path::new(comps.connect("\\").into_string()))
Some(Path::new(comps.connect("\\")))
}
}

Expand Down
42 changes: 18 additions & 24 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,61 +680,55 @@ fn node_id_to_str(map: &Map, id: NodeId) -> String {
ItemImpl(..) => "impl",
ItemMac(..) => "macro"
};
(format!("{} {} (id={})", item_str, path_str, id)).to_string()
format!("{} {} (id={})", item_str, path_str, id)
}
Some(NodeForeignItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
(format!("foreign item {} (id={})", path_str, id)).to_string()
format!("foreign item {} (id={})", path_str, id)
}
Some(NodeMethod(m)) => {
(format!("method {} in {} (id={})",
format!("method {} in {} (id={})",
token::get_ident(m.ident),
map.path_to_str(id), id)).to_string()
map.path_to_str(id), id)
}
Some(NodeTraitMethod(ref tm)) => {
let m = ast_util::trait_method_to_ty_method(&**tm);
(format!("method {} in {} (id={})",
format!("method {} in {} (id={})",
token::get_ident(m.ident),
map.path_to_str(id), id)).to_string()
map.path_to_str(id), id)
}
Some(NodeVariant(ref variant)) => {
(format!("variant {} in {} (id={})",
format!("variant {} in {} (id={})",
token::get_ident(variant.node.name),
map.path_to_str(id), id)).to_string()
map.path_to_str(id), id)
}
Some(NodeExpr(ref expr)) => {
(format!("expr {} (id={})",
pprust::expr_to_str(&**expr), id)).to_string()
format!("expr {} (id={})", pprust::expr_to_str(&**expr), id)
}
Some(NodeStmt(ref stmt)) => {
(format!("stmt {} (id={})",
pprust::stmt_to_str(&**stmt), id)).to_string()
format!("stmt {} (id={})", pprust::stmt_to_str(&**stmt), id)
}
Some(NodeArg(ref pat)) => {
(format!("arg {} (id={})",
pprust::pat_to_str(&**pat), id)).to_string()
format!("arg {} (id={})", pprust::pat_to_str(&**pat), id)
}
Some(NodeLocal(ref pat)) => {
(format!("local {} (id={})",
pprust::pat_to_str(&**pat), id)).to_string()
format!("local {} (id={})", pprust::pat_to_str(&**pat), id)
}
Some(NodePat(ref pat)) => {
(format!("pat {} (id={})", pprust::pat_to_str(&**pat), id)).to_string()
format!("pat {} (id={})", pprust::pat_to_str(&**pat), id)
}
Some(NodeBlock(ref block)) => {
(format!("block {} (id={})",
pprust::block_to_str(&**block), id)).to_string()
format!("block {} (id={})", pprust::block_to_str(&**block), id)
}
Some(NodeStructCtor(_)) => {
(format!("struct_ctor {} (id={})",
map.path_to_str(id), id)).to_string()
format!("struct_ctor {} (id={})", map.path_to_str(id), id)
}
Some(NodeLifetime(ref l)) => {
(format!("lifetime {} (id={})",
pprust::lifetime_to_str(&**l), id)).to_string()
format!("lifetime {} (id={})",
pprust::lifetime_to_str(&**l), id)
}
None => {
(format!("unknown node (id={})", id)).to_string()
format!("unknown node (id={})", id)
}
}
}
Loading