Auto merge of #29615 - steveklabnik:lol_strings, r=alexcrichton

&format!("...") is the same as "" if we're not doing any interpolation,
and doesn't allocate an intermediate String.
This commit is contained in:
bors 2015-11-06 11:28:07 +00:00
commit 2f59977d96
15 changed files with 26 additions and 35 deletions

View File

@ -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,

View File

@ -1232,7 +1232,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")
}
}
}

View File

@ -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(

View File

@ -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");
}
}
}

View File

@ -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(

View File

@ -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");
}
_ => {}
}

View File

@ -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);

View File

@ -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");
}
};

View File

@ -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");
}
}
}

View File

@ -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);

View File

@ -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());

View File

@ -400,9 +400,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
}
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();
}

View File

@ -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"));
}
}
}

View File

@ -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)
}

View File

@ -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()[..]);