Skip to content

Commit 57a5a9b

Browse files
committed
Prefer to_string() to format!()
1 parent 3d0e933 commit 57a5a9b

File tree

36 files changed

+95
-95
lines changed

36 files changed

+95
-95
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl<'a> Builder<'a> {
925925
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
926926
}
927927

928-
cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));
928+
cargo.env("RUSTC_VERBOSE", self.verbosity.to_string());
929929

930930
// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.
931931
if self.config.deny_warnings && !(mode == Mode::Std && stage == 0) {

src/libcore/tests/str_lossy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn chunks() {
7979
fn display() {
8080
assert_eq!(
8181
"Hello\u{FFFD}\u{FFFD} There\u{FFFD} Goodbye",
82-
&format!("{}", Utf8Lossy::from_bytes(b"Hello\xC0\x80 There\xE6\x83 Goodbye")));
82+
&Utf8Lossy::from_bytes(b"Hello\xC0\x80 There\xE6\x83 Goodbye").to_string());
8383
}
8484

8585
#[test]

src/librustc/infer/error_reporting/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
557557
// Output the lifetimes fot the first type
558558
let lifetimes = sub.regions()
559559
.map(|lifetime| {
560-
let s = format!("{}", lifetime);
560+
let s = lifetime.to_string();
561561
if s.is_empty() {
562562
"'_".to_string()
563563
} else {
@@ -582,7 +582,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
582582
value.0.extend((values.0).0);
583583
other_value.0.extend((values.1).0);
584584
} else {
585-
value.push_highlighted(format!("{}", type_arg));
585+
value.push_highlighted(type_arg.to_string());
586586
}
587587

588588
if len > 0 && i != len - 1 {
@@ -716,7 +716,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
716716
mutbl: hir::Mutability,
717717
s: &mut DiagnosticStyledString,
718718
) {
719-
let r = &format!("{}", r);
719+
let r = &r.to_string();
720720
s.push_highlighted(format!(
721721
"&{}{}{}",
722722
r,
@@ -727,7 +727,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
727727
""
728728
}
729729
));
730-
s.push_normal(format!("{}", ty));
730+
s.push_normal(ty.to_string());
731731
}
732732

733733
match (&t1.sty, &t2.sty) {
@@ -768,7 +768,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
768768
}
769769

770770
fn lifetime_display(lifetime: Region) -> String {
771-
let s = format!("{}", lifetime);
771+
let s = lifetime.to_string();
772772
if s.is_empty() {
773773
"'_".to_string()
774774
} else {
@@ -863,8 +863,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
863863
// We couldn't find anything in common, highlight everything.
864864
// let x: Bar<Qux> = y::<Foo<Zar>>();
865865
(
866-
DiagnosticStyledString::highlighted(format!("{}", t1)),
867-
DiagnosticStyledString::highlighted(format!("{}", t2)),
866+
DiagnosticStyledString::highlighted(t1.to_string()),
867+
DiagnosticStyledString::highlighted(t2.to_string()),
868868
)
869869
}
870870
}
@@ -873,12 +873,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
873873
(&ty::TyRef(r1, ref_ty1, mutbl1), _) if equals(&ref_ty1, &t2) => {
874874
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
875875
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
876-
values.1.push_normal(format!("{}", t2));
876+
values.1.push_normal(t2.to_string());
877877
values
878878
}
879879
(_, &ty::TyRef(r2, ref_ty2, mutbl2)) if equals(&t1, &ref_ty2) => {
880880
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
881-
values.0.push_normal(format!("{}", t1));
881+
values.0.push_normal(t1.to_string());
882882
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
883883
values
884884
}
@@ -902,8 +902,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
902902
} else {
903903
// We couldn't find anything in common, highlight everything.
904904
(
905-
DiagnosticStyledString::highlighted(format!("{}", t1)),
906-
DiagnosticStyledString::highlighted(format!("{}", t2)),
905+
DiagnosticStyledString::highlighted(t1.to_string()),
906+
DiagnosticStyledString::highlighted(t2.to_string()),
907907
)
908908
}
909909
}
@@ -1073,8 +1073,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10731073
}
10741074

10751075
Some((
1076-
DiagnosticStyledString::highlighted(format!("{}", exp_found.expected)),
1077-
DiagnosticStyledString::highlighted(format!("{}", exp_found.found)),
1076+
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
1077+
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
10781078
))
10791079
}
10801080

src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
5757
let lifetime_name = match sup_r {
5858
RegionKind::ReFree(FreeRegion {
5959
bound_region: BoundRegion::BrNamed(_, ref name), ..
60-
}) => format!("{}", name),
60+
}) => name.to_string(),
6161
_ => "'_".to_owned(),
6262
};
6363
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(return_sp) {

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
20932093

20942094
// When printing regions, add trailing space if necessary.
20952095
let region = if ppaux::verbose() || ppaux::identify_regions() {
2096-
let mut region = format!("{}", region);
2096+
let mut region = region.to_string();
20972097
if region.len() > 0 {
20982098
region.push(' ');
20992099
}

src/librustc/session/code_stats.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl CodeStats {
135135
let VariantInfo { ref name, kind: _, align: _, size, ref fields } = *variant_info;
136136
let indent = if !struct_like {
137137
let name = match name.as_ref() {
138-
Some(name) => format!("{}", name),
139-
None => format!("{}", i),
138+
Some(name) => name.to_owned(),
139+
None => i.to_string(),
140140
};
141141
println!("print-type-size {}variant `{}`: {} bytes",
142142
indent, name, size - discr_size);

src/librustc/traits/error_reporting.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
543543
&data.parent_trait_ref);
544544
match self.get_parent_trait_ref(&data.parent_code) {
545545
Some(t) => Some(t),
546-
None => Some(format!("{}", parent_trait_ref.skip_binder().self_ty())),
546+
None => Some(parent_trait_ref.skip_binder().self_ty().to_string()),
547547
}
548548
}
549549
_ => None,
@@ -797,12 +797,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
797797
ty::TypeVariants::TyTuple(ref tys) => ArgKind::Tuple(
798798
Some(span),
799799
tys.iter()
800-
.map(|ty| ("_".to_owned(), format!("{}", ty.sty)))
800+
.map(|ty| ("_".to_owned(), ty.sty.to_string()))
801801
.collect::<Vec<_>>()
802802
),
803-
_ => ArgKind::Arg("_".to_owned(), format!("{}", t.sty)),
803+
_ => ArgKind::Arg("_".to_owned(), t.sty.to_string()),
804804
}).collect(),
805-
ref sty => vec![ArgKind::Arg("_".to_owned(), format!("{}", sty))],
805+
ref sty => vec![ArgKind::Arg("_".to_owned(), sty.to_string())],
806806
};
807807
if found.len() == expected.len() {
808808
self.report_closure_arg_mismatch(span,
@@ -989,7 +989,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
989989
}) => {
990990
(self.tcx.sess.codemap().def_span(span),
991991
fields.iter().map(|field| {
992-
ArgKind::Arg(format!("{}", field.ident), "_".to_string())
992+
ArgKind::Arg(field.ident.to_string(), "_".to_string())
993993
}).collect::<Vec<_>>())
994994
}
995995
hir::map::NodeStructCtor(ref variant_data) => {
@@ -1152,7 +1152,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11521152
::rustc_target::spec::abi::Abi::Rust
11531153
)
11541154
};
1155-
format!("{}", ty::Binder::bind(sig))
1155+
ty::Binder::bind(sig).to_string()
11561156
}
11571157

11581158
let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
@@ -1575,10 +1575,10 @@ impl ArgKind {
15751575
ty::TyTuple(ref tys) => ArgKind::Tuple(
15761576
None,
15771577
tys.iter()
1578-
.map(|ty| ("_".to_owned(), format!("{}", ty.sty)))
1578+
.map(|ty| ("_".to_owned(), ty.sty.to_string()))
15791579
.collect::<Vec<_>>()
15801580
),
1581-
_ => ArgKind::Arg("_".to_owned(), format!("{}", t.sty)),
1581+
_ => ArgKind::Arg("_".to_owned(), t.sty.to_string()),
15821582
}
15831583
}
15841584
}

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
315315
ty::TyUint(_) |
316316
ty::TyFloat(_) |
317317
ty::TyStr => {
318-
buffer.push(&format!("{}", self_ty));
318+
buffer.push(&self_ty.to_string());
319319
}
320320

321321
_ => {

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl AssociatedItem {
225225
// late-bound regions, and we don't want method signatures to show up
226226
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
227227
// regions just fine, showing `fn(&MyType)`.
228-
format!("{}", tcx.fn_sig(self.def_id).skip_binder())
228+
tcx.fn_sig(self.def_id).skip_binder().to_string()
229229
}
230230
ty::AssociatedKind::Type => format!("type {};", self.ident),
231231
ty::AssociatedKind::Existential => format!("existential type {};", self.ident),

src/librustc/util/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn to_readable_str(mut val: usize) -> String {
243243
val /= 1000;
244244

245245
if val == 0 {
246-
groups.push(format!("{}", group));
246+
groups.push(group.to_string());
247247
break;
248248
} else {
249249
groups.push(format!("{:03}", group));

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
683683
let mut err = self.cannot_act_on_moved_value(use_span,
684684
verb,
685685
msg,
686-
Some(format!("{}", nl)),
686+
Some(nl.to_string()),
687687
Origin::Ast);
688688
let need_note = match lp.ty.sty {
689689
ty::TypeVariants::TyClosure(id, _) => {

src/librustc_codegen_llvm/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> ArchiveBuilder<'a> {
149149
// Ignoring obj file starting with the crate name
150150
// as simple comparison is not enough - there
151151
// might be also an extra name suffix
152-
let obj_start = format!("{}", name);
152+
let obj_start = name.to_owned();
153153

154154
self.add_archive(rlib, move |fname: &str| {
155155
// Ignore bytecode/metadata files, no matter the name.

src/librustc_codegen_llvm/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ fn link_natively(sess: &Session,
810810
}
811811
};
812812

813-
linker_error.note(&format!("{}", e));
813+
linker_error.note(&e.to_string());
814814

815815
if !linker_not_found {
816816
linker_error.note(&format!("{:?}", &cmd));

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ fn run_compiler_with_pool<'a>(
533533
if let Some(err) = input_err {
534534
// Immediately stop compilation if there was an issue reading
535535
// the input (for example if the input stream is not UTF-8).
536-
sess.err(&format!("{}", err));
536+
sess.err(&err.to_string());
537537
return (Err(CompileIncomplete::Stopped), Some(sess));
538538
}
539539

@@ -1113,7 +1113,7 @@ impl RustcDefaultCalls {
11131113
cfgs.push(if let Some(value) = value {
11141114
format!("{}=\"{}\"", name, value)
11151115
} else {
1116-
format!("{}", name)
1116+
name.to_string()
11171117
});
11181118
}
11191119

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
190190
fieldpat.span,
191191
&format!("the `{}:` in this pattern is redundant", ident));
192192
let subspan = cx.tcx.sess.codemap().span_through_char(fieldpat.span, ':');
193-
err.span_suggestion_short(subspan, "remove this", format!("{}", ident));
193+
err.span_suggestion_short(subspan, "remove this", ident.to_string());
194194
err.emit();
195195
}
196196
}
@@ -701,7 +701,7 @@ impl EarlyLintPass for BadRepr {
701701
attr.span,
702702
"`repr` attribute isn't configurable with a literal",
703703
);
704-
match format!("{}", lit).as_ref() {
704+
match lit.to_string().as_ref() {
705705
| "C" | "packed" | "rust" | "transparent"
706706
| "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
707707
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => {

src/librustc_metadata/locator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl<'a> Context<'a> {
722722
root.triple);
723723
self.rejected_via_triple.push(CrateMismatch {
724724
path: libpath.to_path_buf(),
725-
got: format!("{}", root.triple),
725+
got: root.triple.to_string(),
726726
});
727727
return None;
728728
}

src/librustc_mir/borrow_check/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
8686
mir::BorrowKind::Unique => "uniq ",
8787
mir::BorrowKind::Mut { .. } => "mut ",
8888
};
89-
let region = format!("{}", self.region);
89+
let region = self.region.to_string();
9090
let region = if region.len() > 0 {
9191
format!("{} ", region)
9292
} else {

src/librustc_mir/borrow_check/error_reporting.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
642642
self.append_local_to_string(local, buf)?;
643643
}
644644
Place::Static(ref static_) => {
645-
buf.push_str(&format!("{}", &self.tcx.item_name(static_.def_id)));
645+
buf.push_str(&self.tcx.item_name(static_.def_id).to_string());
646646
}
647647
Place::Projection(ref proj) => {
648648
match proj.elem {
@@ -766,7 +766,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
766766
let local = &self.mir.local_decls[local_index];
767767
match local.name {
768768
Some(name) => {
769-
buf.push_str(&format!("{}", name));
769+
buf.push_str(&name.to_string());
770770
Ok(())
771771
}
772772
None => Err(()),
@@ -794,7 +794,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
794794
ProjectionElem::Index(..)
795795
| ProjectionElem::ConstantIndex { .. }
796796
| ProjectionElem::Subslice { .. } => {
797-
format!("{}", self.describe_field(&proj.base, field))
797+
self.describe_field(&proj.base, field).to_string()
798798
}
799799
},
800800
}
@@ -808,11 +808,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
808808
} else {
809809
match ty.sty {
810810
ty::TyAdt(def, _) => if def.is_enum() {
811-
format!("{}", field.index())
811+
field.index().to_string()
812812
} else {
813-
format!("{}", def.non_enum_variant().fields[field.index()].ident)
813+
def.non_enum_variant().fields[field.index()].ident.to_string()
814814
},
815-
ty::TyTuple(_) => format!("{}", field.index()),
815+
ty::TyTuple(_) => field.index().to_string(),
816816
ty::TyRef(_, ty, _) | ty::TyRawPtr(ty::TypeAndMut { ty, .. }) => {
817817
self.describe_field_from_ty(&ty, field)
818818
}

src/librustc_mir/borrow_check/flows.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
114114
};
115115
saw_one = true;
116116
let borrow_data = &self.borrows.operator().borrows()[borrow];
117-
s.push_str(&format!("{}", borrow_data));
117+
s.push_str(&borrow_data.to_string());
118118
});
119119
s.push_str("] ");
120120

@@ -126,7 +126,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
126126
};
127127
saw_one = true;
128128
let borrow_data = &self.borrows.operator().borrows()[borrow];
129-
s.push_str(&format!("{}", borrow_data));
129+
s.push_str(&borrow_data.to_string());
130130
});
131131
s.push_str("] ");
132132

@@ -138,7 +138,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
138138
};
139139
saw_one = true;
140140
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
141-
s.push_str(&format!("{}", move_path));
141+
s.push_str(&move_path.to_string());
142142
});
143143
s.push_str("] ");
144144

src/librustc_mir/borrow_check/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
312312
err.span_suggestion(
313313
span,
314314
"consider removing this dereference operator",
315-
format!("{}", &snippet[1..]),
315+
(&snippet[1..]).to_owned(),
316316
);
317317
}
318318
_ => {

src/librustc_traits/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx> {
523523
Clause::Implies(program_clause) => program_clause,
524524
Clause::ForAll(program_clause) => program_clause.skip_binder(),
525525
};
526-
format!("{}", program_clause)
526+
program_clause.to_string()
527527
})
528528
.collect();
529529

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28382838
ty::TyFnDef(..) => {
28392839
let ptr_ty = self.tcx.mk_fn_ptr(arg_ty.fn_sig(self.tcx));
28402840
let ptr_ty = self.resolve_type_vars_if_possible(&ptr_ty);
2841-
variadic_error(tcx.sess, arg.span, arg_ty, &format!("{}", ptr_ty));
2841+
variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string());
28422842
}
28432843
_ => {}
28442844
}

0 commit comments

Comments
 (0)