From f8e06c49650afd7c9ef749baa72cb8da59880f96 Mon Sep 17 00:00:00 2001 From: Piotr Jawniak Date: Thu, 26 Jun 2014 08:15:14 +0200 Subject: Remove unnecessary to_string calls This commit removes superfluous to_string calls from various places --- src/libsyntax/ast_map.rs | 42 +++++++++++++------------------ src/libsyntax/ast_util.rs | 6 ++--- src/libsyntax/crateid.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/parse/lexer/comments.rs | 2 +- src/libsyntax/print/pp.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- 7 files changed, 26 insertions(+), 32 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 828e9ab12c2..1a9a910f38c 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -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) } } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index df8cb328270..2a6f7bdb87e 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -30,7 +30,7 @@ pub fn path_name_i(idents: &[Ident]) -> String { // FIXME: Bad copies (#2543 -- same for everything else that says "bad") idents.iter().map(|i| { token::get_ident(*i).get().to_string() - }).collect::>().connect("::").to_string() + }).collect::>().connect("::") } // totally scary function: ignores all but the last element, should have @@ -123,7 +123,7 @@ pub fn int_ty_to_str(t: IntTy, val: Option) -> String { // cast to a u64 so we can correctly print INT64_MIN. All integral types // are parsed as u64, so we wouldn't want to print an extra negative // sign. - Some(n) => format!("{}{}", n as u64, s).to_string(), + Some(n) => format!("{}{}", n as u64, s), None => s.to_string() } } @@ -150,7 +150,7 @@ pub fn uint_ty_to_str(t: UintTy, val: Option) -> String { }; match val { - Some(n) => format!("{}{}", n, s).to_string(), + Some(n) => format!("{}{}", n, s), None => s.to_string() } } diff --git a/src/libsyntax/crateid.rs b/src/libsyntax/crateid.rs index a3112cbb8be..b9298cca4f8 100644 --- a/src/libsyntax/crateid.rs +++ b/src/libsyntax/crateid.rs @@ -112,7 +112,7 @@ impl CrateId { } pub fn short_name_with_version(&self) -> String { - (format!("{}-{}", self.name, self.version_or_default())).to_string() + format!("{}-{}", self.name, self.version_or_default()) } pub fn matches(&self, other: &CrateId) -> bool { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 05269dbb44d..2b97687dbf8 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1015,7 +1015,7 @@ impl<'a> TraitDef<'a> { to_set.expn_info = Some(box(GC) codemap::ExpnInfo { call_site: to_set, callee: codemap::NameAndSpan { - name: format!("deriving({})", trait_name).to_string(), + name: format!("deriving({})", trait_name), format: codemap::MacroAttribute, span: Some(self.span) } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index a009955f91a..f00c1ab4455 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -135,7 +135,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let lines = vertical_trim(lines); let lines = horizontal_trim(lines); - return lines.connect("\n").to_string(); + return lines.connect("\n"); } fail!("not a doc-comment: {}", comment); diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 854aa80ca34..24ab4b38e54 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -111,7 +111,7 @@ impl Token { pub fn tok_str(t: Token) -> String { match t { - String(s, len) => return format!("STR({},{})", s, len).to_string(), + String(s, len) => return format!("STR({},{})", s, len), Break(_) => return "BREAK".to_string(), Begin(_) => return "BEGIN".to_string(), End => return "END".to_string(), diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 97e99ca692d..87ed2076d61 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -243,7 +243,7 @@ pub fn arg_to_str(arg: &ast::Arg) -> String { pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String { match vis { - ast::Public => format!("pub {}", s).to_string(), + ast::Public => format!("pub {}", s), ast::Inherited => s.to_string() } } -- cgit 1.4.1-3-g733a5