From 63576c23e41092ae16c57e15977bf10e72327799 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 5 Nov 2015 15:30:32 +0100 Subject: [PATCH] remove excess string allocation &format!("...") is the same as "" if we're not doing any interpolation, and doesn't allocate an intermediate String. --- src/librustc/middle/check_const.rs | 2 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/infer/error_reporting.rs | 2 +- src/librustc/middle/infer/mod.rs | 2 +- src/librustc/middle/traits/error_reporting.rs | 2 +- src/librustc/middle/ty/error.rs | 15 ++++++--------- src/librustc_mir/build/expr/as_temp.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 8 +++----- src/librustc_mir/mir_map.rs | 2 +- src/librustc_typeck/check/intrinsic.rs | 6 ++---- src/libstd/fs.rs | 2 +- src/libsyntax/ext/expand.rs | 4 +--- src/libsyntax/parse/parser.rs | 2 +- .../issue-23338-ensure-param-drop-order.rs | 8 ++++---- .../run-pass/issue-23611-enum-swap-in-drop.rs | 2 +- 15 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 76fa54317fc11..a3eeb12da0114 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -225,7 +225,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { { self.tcx.sess.span_err( expr.span, - &format!("const fns are an unstable feature")); + "const fns are an unstable feature"); fileline_help!( self.tcx.sess, expr.span, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 1651e71c49a2a..c461057c6cd8d 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1213,7 +1213,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, _ => { tcx.sess.span_bug( ti.span, - &format!("resolve_trait_associated_const: unexpected vtable type")) + "resolve_trait_associated_const: unexpected vtable type") } } } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 0ab572c543b29..a16ef808bb6d3 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -1751,7 +1751,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> { infer::ParameterInScope(_, span) => { self.tcx.sess.span_note( span, - &format!("...so that a type/lifetime parameter is in scope here")); + "...so that a type/lifetime parameter is in scope here"); } infer::DataBorrowed(ty, span) => { self.tcx.sess.span_note( diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index f80c486f237b1..684e60304eb4d 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -1130,7 +1130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { match self.tables.borrow().node_types.get(&ex.id) { Some(&t) => t, None => { - self.tcx.sess.bug(&format!("no type for expr in fcx")); + self.tcx.sess.bug("no type for expr in fcx"); } } } diff --git a/src/librustc/middle/traits/error_reporting.rs b/src/librustc/middle/traits/error_reporting.rs index a54818b2b5369..0931c138e46f4 100644 --- a/src/librustc/middle/traits/error_reporting.rs +++ b/src/librustc/middle/traits/error_reporting.rs @@ -498,7 +498,7 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, ObligationCauseCode::SliceOrArrayElem => { tcx.sess.fileline_note( cause_span, - &format!("slice and array elements must have `Sized` type")); + "slice and array elements must have `Sized` type"); } ObligationCauseCode::ProjectionWf(data) => { tcx.sess.fileline_note( diff --git a/src/librustc/middle/ty/error.rs b/src/librustc/middle/ty/error.rs index 61536934aae13..d9033eaa29f6b 100644 --- a/src/librustc/middle/ty/error.rs +++ b/src/librustc/middle/ty/error.rs @@ -288,10 +288,9 @@ impl<'tcx> ty::ctxt<'tcx> { let found_str = values.found.sort_string(self); if expected_str == found_str && expected_str == "closure" { self.sess.span_note(sp, - &format!("no two closures, even if identical, have the same type")); + "no two closures, even if identical, have the same type"); self.sess.span_help(sp, - &format!("consider boxing your closure and/or \ - using it as a trait object")); + "consider boxing your closure and/or using it as a trait object"); } }, TyParamDefaultMismatch(values) => { @@ -307,8 +306,7 @@ impl<'tcx> ty::ctxt<'tcx> { .and_then(|node_id| self.map.opt_span(node_id)) { Some(span) => { - self.sess.span_note(span, - &format!("a default was defined here...")); + self.sess.span_note(span, "a default was defined here..."); } None => { self.sess.note( @@ -319,15 +317,14 @@ impl<'tcx> ty::ctxt<'tcx> { self.sess.span_note( expected.origin_span, - &format!("...that was applied to an unconstrained type variable here")); + "...that was applied to an unconstrained type variable here"); match self.map.as_local_node_id(found.def_id) .and_then(|node_id| self.map.opt_span(node_id)) { Some(span) => { - self.sess.span_note(span, - &format!("a second default was defined here...")); + self.sess.span_note(span, "a second default was defined here..."); } None => { self.sess.note( @@ -338,7 +335,7 @@ impl<'tcx> ty::ctxt<'tcx> { self.sess.span_note( found.origin_span, - &format!("...that also applies to the same type variable here")); + "...that also applies to the same type variable here"); } _ => {} } diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index 7c85e9e717463..f0bbc6fb67eaa 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -38,7 +38,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { let temp_lifetime = match expr.temp_lifetime { Some(t) => t, None => { - this.hir.span_bug(expr.span, &format!("no temp_lifetime for expr")); + this.hir.span_bug(expr.span, "no temp_lifetime for expr"); } }; this.schedule_drop(expr.span, temp_lifetime, DropKind::Deep, &temp, expr_ty); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 847d76f7d17a9..a077cb6c7a3a5 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -236,7 +236,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { let (adt_def, substs) = match range_ty.sty { ty::TyStruct(adt_def, substs) => (adt_def, substs), _ => { - cx.tcx.sess.span_bug(self.span, &format!("unexpanded ast")); + cx.tcx.sess.span_bug(self.span, "unexpanded ast"); } }; @@ -555,14 +555,12 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, match expr.node { hir::ExprClosure(_, _, ref body) => body.id, _ => { - cx.tcx.sess.span_bug(expr.span, - &format!("closure expr is not a closure expr")); + cx.tcx.sess.span_bug(expr.span, "closure expr is not a closure expr"); } } } _ => { - cx.tcx.sess.span_bug(expr.span, - &format!("ast-map has garbage for closure expr")); + cx.tcx.sess.span_bug(expr.span, "ast-map has garbage for closure expr"); } }; diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index ebcb1db1151ee..4302105dda2b7 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -173,7 +173,7 @@ impl<'a, 'm, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'m,'tcx> { None => { self.tcx.sess.span_err( item.span, - &format!("graphviz attribute requires a path")); + "graphviz attribute requires a path"); } } } diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 0ab0f1f9c1de1..b9fec44ec4030 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -458,14 +458,12 @@ fn match_intrinsic_type_to_type<'tcx, 'a>( match_intrinsic_type_to_type(tcx, position, span, structural_to_nominal, inner_expected, ty) } - _ => simple_error(&format!("`{}`", t), - &format!("raw pointer")), + _ => simple_error(&format!("`{}`", t), "raw pointer"), } } Vector(ref inner_expected, ref _llvm_type, len) => { if !t.is_simd() { - simple_error(&format!("non-simd type `{}`", t), - "simd type"); + simple_error(&format!("non-simd type `{}`", t), "simd type"); return; } let t_len = t.simd_size(tcx); diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 6178f1bbb8e12..03b8b455299e9 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1732,7 +1732,7 @@ mod tests { let tmpdir = tmpdir(); let mut dirpath = tmpdir.path().to_path_buf(); - dirpath.push(&format!("test-가一ー你好")); + dirpath.push("test-가一ー你好"); check!(fs::create_dir(&dirpath)); assert!(dirpath.is_dir()); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b1b4605d5ec65..512f71fd4c191 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -400,9 +400,7 @@ pub fn expand_item_mac(it: P, } MacroRulesTT => { if ident.name == parse::token::special_idents::invalid.name { - fld.cx.span_err(path_span, - &format!("macro_rules! expects an ident argument") - ); + fld.cx.span_err(path_span, "macro_rules! expects an ident argument"); return SmallVector::zero(); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2401f6be78f9c..7da03c7482c91 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1843,7 +1843,7 @@ impl<'a> Parser<'a> { }); } _ => { - return Err(self.fatal(&format!("expected a lifetime name"))); + return Err(self.fatal("expected a lifetime name")); } } } diff --git a/src/test/run-pass/issue-23338-ensure-param-drop-order.rs b/src/test/run-pass/issue-23338-ensure-param-drop-order.rs index 0815ff084fb51..507d482febfd9 100644 --- a/src/test/run-pass/issue-23338-ensure-param-drop-order.rs +++ b/src/test/run-pass/issue-23338-ensure-param-drop-order.rs @@ -19,7 +19,7 @@ use self::d::D; pub fn main() { let log = RefCell::new(vec![]); - d::println(&format!("created empty log")); + d::println("created empty log"); test(&log); assert_eq!(&log.borrow()[..], @@ -59,19 +59,19 @@ pub fn main() { fn test<'a>(log: d::Log<'a>) { let da = D::new("da", 0, log); let de = D::new("de", 1, log); - d::println(&format!("calling foo")); + d::println("calling foo"); let result = foo(da, de); d::println(&format!("result {}", result)); } fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> { - d::println(&format!("entered foo")); + d::println("entered foo"); let de2 = de1.incr(); // creates D(de_2, 2) let de4 = { let _da1 = da0.incr(); // creates D(da_1, 3) de2.incr().incr() // creates D(de_3, 4) and D(de_4, 5) }; - d::println(&format!("eval tail of foo")); + d::println("eval tail of foo"); de4.incr().incr() // creates D(de_5, 6) and D(de_6, 7) } diff --git a/src/test/run-pass/issue-23611-enum-swap-in-drop.rs b/src/test/run-pass/issue-23611-enum-swap-in-drop.rs index 540cbd50e9d57..09bc3fd0214e7 100644 --- a/src/test/run-pass/issue-23611-enum-swap-in-drop.rs +++ b/src/test/run-pass/issue-23611-enum-swap-in-drop.rs @@ -20,7 +20,7 @@ use self::d::D; pub fn main() { let log = RefCell::new(vec![]); - d::println(&format!("created empty log")); + d::println("created empty log"); test(&log); // println!("log: {:?}", &log.borrow()[..]);