Skip to content

Commit 2f59977

Browse files
committed
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.
2 parents 6878fce + 63576c2 commit 2f59977

File tree

15 files changed

+26
-35
lines changed

15 files changed

+26
-35
lines changed

Diff for: src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
225225
{
226226
self.tcx.sess.span_err(
227227
expr.span,
228-
&format!("const fns are an unstable feature"));
228+
"const fns are an unstable feature");
229229
fileline_help!(
230230
self.tcx.sess,
231231
expr.span,

Diff for: src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
12321232
_ => {
12331233
tcx.sess.span_bug(
12341234
ti.span,
1235-
&format!("resolve_trait_associated_const: unexpected vtable type"))
1235+
"resolve_trait_associated_const: unexpected vtable type")
12361236
}
12371237
}
12381238
}

Diff for: src/librustc/middle/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
17511751
infer::ParameterInScope(_, span) => {
17521752
self.tcx.sess.span_note(
17531753
span,
1754-
&format!("...so that a type/lifetime parameter is in scope here"));
1754+
"...so that a type/lifetime parameter is in scope here");
17551755
}
17561756
infer::DataBorrowed(ty, span) => {
17571757
self.tcx.sess.span_note(

Diff for: src/librustc/middle/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11301130
match self.tables.borrow().node_types.get(&ex.id) {
11311131
Some(&t) => t,
11321132
None => {
1133-
self.tcx.sess.bug(&format!("no type for expr in fcx"));
1133+
self.tcx.sess.bug("no type for expr in fcx");
11341134
}
11351135
}
11361136
}

Diff for: src/librustc/middle/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
498498
ObligationCauseCode::SliceOrArrayElem => {
499499
tcx.sess.fileline_note(
500500
cause_span,
501-
&format!("slice and array elements must have `Sized` type"));
501+
"slice and array elements must have `Sized` type");
502502
}
503503
ObligationCauseCode::ProjectionWf(data) => {
504504
tcx.sess.fileline_note(

Diff for: src/librustc/middle/ty/error.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ impl<'tcx> ty::ctxt<'tcx> {
288288
let found_str = values.found.sort_string(self);
289289
if expected_str == found_str && expected_str == "closure" {
290290
self.sess.span_note(sp,
291-
&format!("no two closures, even if identical, have the same type"));
291+
"no two closures, even if identical, have the same type");
292292
self.sess.span_help(sp,
293-
&format!("consider boxing your closure and/or \
294-
using it as a trait object"));
293+
"consider boxing your closure and/or using it as a trait object");
295294
}
296295
},
297296
TyParamDefaultMismatch(values) => {
@@ -307,8 +306,7 @@ impl<'tcx> ty::ctxt<'tcx> {
307306
.and_then(|node_id| self.map.opt_span(node_id))
308307
{
309308
Some(span) => {
310-
self.sess.span_note(span,
311-
&format!("a default was defined here..."));
309+
self.sess.span_note(span, "a default was defined here...");
312310
}
313311
None => {
314312
self.sess.note(
@@ -319,15 +317,14 @@ impl<'tcx> ty::ctxt<'tcx> {
319317

320318
self.sess.span_note(
321319
expected.origin_span,
322-
&format!("...that was applied to an unconstrained type variable here"));
320+
"...that was applied to an unconstrained type variable here");
323321

324322
match
325323
self.map.as_local_node_id(found.def_id)
326324
.and_then(|node_id| self.map.opt_span(node_id))
327325
{
328326
Some(span) => {
329-
self.sess.span_note(span,
330-
&format!("a second default was defined here..."));
327+
self.sess.span_note(span, "a second default was defined here...");
331328
}
332329
None => {
333330
self.sess.note(
@@ -338,7 +335,7 @@ impl<'tcx> ty::ctxt<'tcx> {
338335

339336
self.sess.span_note(
340337
found.origin_span,
341-
&format!("...that also applies to the same type variable here"));
338+
"...that also applies to the same type variable here");
342339
}
343340
_ => {}
344341
}

Diff for: src/librustc_mir/build/expr/as_temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3838
let temp_lifetime = match expr.temp_lifetime {
3939
Some(t) => t,
4040
None => {
41-
this.hir.span_bug(expr.span, &format!("no temp_lifetime for expr"));
41+
this.hir.span_bug(expr.span, "no temp_lifetime for expr");
4242
}
4343
};
4444
this.schedule_drop(expr.span, temp_lifetime, DropKind::Deep, &temp, expr_ty);

Diff for: src/librustc_mir/hair/cx/expr.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
236236
let (adt_def, substs) = match range_ty.sty {
237237
ty::TyStruct(adt_def, substs) => (adt_def, substs),
238238
_ => {
239-
cx.tcx.sess.span_bug(self.span, &format!("unexpanded ast"));
239+
cx.tcx.sess.span_bug(self.span, "unexpanded ast");
240240
}
241241
};
242242

@@ -555,14 +555,12 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
555555
match expr.node {
556556
hir::ExprClosure(_, _, ref body) => body.id,
557557
_ => {
558-
cx.tcx.sess.span_bug(expr.span,
559-
&format!("closure expr is not a closure expr"));
558+
cx.tcx.sess.span_bug(expr.span, "closure expr is not a closure expr");
560559
}
561560
}
562561
}
563562
_ => {
564-
cx.tcx.sess.span_bug(expr.span,
565-
&format!("ast-map has garbage for closure expr"));
563+
cx.tcx.sess.span_bug(expr.span, "ast-map has garbage for closure expr");
566564
}
567565
};
568566

Diff for: src/librustc_mir/mir_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a, 'm, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'m,'tcx> {
173173
None => {
174174
self.tcx.sess.span_err(
175175
item.span,
176-
&format!("graphviz attribute requires a path"));
176+
"graphviz attribute requires a path");
177177
}
178178
}
179179
}

Diff for: src/librustc_typeck/check/intrinsic.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,12 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
458458
match_intrinsic_type_to_type(tcx, position, span, structural_to_nominal,
459459
inner_expected, ty)
460460
}
461-
_ => simple_error(&format!("`{}`", t),
462-
&format!("raw pointer")),
461+
_ => simple_error(&format!("`{}`", t), "raw pointer"),
463462
}
464463
}
465464
Vector(ref inner_expected, ref _llvm_type, len) => {
466465
if !t.is_simd() {
467-
simple_error(&format!("non-simd type `{}`", t),
468-
"simd type");
466+
simple_error(&format!("non-simd type `{}`", t), "simd type");
469467
return;
470468
}
471469
let t_len = t.simd_size(tcx);

Diff for: src/libstd/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ mod tests {
17321732
let tmpdir = tmpdir();
17331733

17341734
let mut dirpath = tmpdir.path().to_path_buf();
1735-
dirpath.push(&format!("test-가一ー你好"));
1735+
dirpath.push("test-가一ー你好");
17361736
check!(fs::create_dir(&dirpath));
17371737
assert!(dirpath.is_dir());
17381738

Diff for: src/libsyntax/ext/expand.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
400400
}
401401
MacroRulesTT => {
402402
if ident.name == parse::token::special_idents::invalid.name {
403-
fld.cx.span_err(path_span,
404-
&format!("macro_rules! expects an ident argument")
405-
);
403+
fld.cx.span_err(path_span, "macro_rules! expects an ident argument");
406404
return SmallVector::zero();
407405
}
408406

Diff for: src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ impl<'a> Parser<'a> {
18431843
});
18441844
}
18451845
_ => {
1846-
return Err(self.fatal(&format!("expected a lifetime name")));
1846+
return Err(self.fatal("expected a lifetime name"));
18471847
}
18481848
}
18491849
}

Diff for: src/test/run-pass/issue-23338-ensure-param-drop-order.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use self::d::D;
1919

2020
pub fn main() {
2121
let log = RefCell::new(vec![]);
22-
d::println(&format!("created empty log"));
22+
d::println("created empty log");
2323
test(&log);
2424

2525
assert_eq!(&log.borrow()[..],
@@ -59,19 +59,19 @@ pub fn main() {
5959
fn test<'a>(log: d::Log<'a>) {
6060
let da = D::new("da", 0, log);
6161
let de = D::new("de", 1, log);
62-
d::println(&format!("calling foo"));
62+
d::println("calling foo");
6363
let result = foo(da, de);
6464
d::println(&format!("result {}", result));
6565
}
6666

6767
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
68-
d::println(&format!("entered foo"));
68+
d::println("entered foo");
6969
let de2 = de1.incr(); // creates D(de_2, 2)
7070
let de4 = {
7171
let _da1 = da0.incr(); // creates D(da_1, 3)
7272
de2.incr().incr() // creates D(de_3, 4) and D(de_4, 5)
7373
};
74-
d::println(&format!("eval tail of foo"));
74+
d::println("eval tail of foo");
7575
de4.incr().incr() // creates D(de_5, 6) and D(de_6, 7)
7676
}
7777

Diff for: src/test/run-pass/issue-23611-enum-swap-in-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use self::d::D;
2020

2121
pub fn main() {
2222
let log = RefCell::new(vec![]);
23-
d::println(&format!("created empty log"));
23+
d::println("created empty log");
2424
test(&log);
2525

2626
// println!("log: {:?}", &log.borrow()[..]);

0 commit comments

Comments
 (0)