Skip to content

Commit c8f9c72

Browse files
authoredSep 10, 2020
Rollup merge of rust-lang#76567 - matthiaskrgr:clone_on_copy, r=varkor
use push(char) to add chars (single-char &strs) to strings instead of push_str(&str)
2 parents 94ae5d1 + 9bb10cc commit c8f9c72

File tree

13 files changed

+33
-31
lines changed

13 files changed

+33
-31
lines changed
 

‎compiler/rustc_builtin_macros/src/format_foreign.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ pub mod printf {
166166
let cap = self.span.len() + if has_options { 2 } else { 0 };
167167
let mut s = String::with_capacity(cap);
168168

169-
s.push_str("{");
169+
s.push('{');
170170

171171
if let Some(arg) = self.parameter {
172172
write!(s, "{}", arg.checked_sub(1)?).ok()?;
173173
}
174174

175175
if has_options {
176-
s.push_str(":");
176+
s.push(':');
177177

178178
let align = if let Some(fill) = fill {
179179
s.push_str(fill);
@@ -191,19 +191,19 @@ pub mod printf {
191191
}
192192

193193
if alt {
194-
s.push_str("#");
194+
s.push('#');
195195
}
196196

197197
if zero_fill {
198-
s.push_str("0");
198+
s.push('0');
199199
}
200200

201201
if let Some(width) = width {
202202
width.translate(&mut s).ok()?;
203203
}
204204

205205
if let Some(precision) = precision {
206-
s.push_str(".");
206+
s.push('.');
207207
precision.translate(&mut s).ok()?;
208208
}
209209

@@ -212,7 +212,7 @@ pub mod printf {
212212
}
213213
}
214214

215-
s.push_str("}");
215+
s.push('}');
216216
Some(s)
217217
}
218218
}

‎compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ fn exec_linker(
10761076
}
10771077
.to_string(),
10781078
);
1079-
args.push_str("\n");
1079+
args.push('\n');
10801080
}
10811081
let file = tmpdir.join("linker-arguments");
10821082
let bytes = if sess.target.target.options.is_like_msvc {

‎compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn push_debuginfo_type_name<'tcx>(
3737
ty::Bool => output.push_str("bool"),
3838
ty::Char => output.push_str("char"),
3939
ty::Str => output.push_str("str"),
40-
ty::Never => output.push_str("!"),
40+
ty::Never => output.push('!'),
4141
ty::Int(int_ty) => output.push_str(int_ty.name_str()),
4242
ty::Uint(uint_ty) => output.push_str(uint_ty.name_str()),
4343
ty::Float(float_ty) => output.push_str(float_ty.name_str()),

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20932093
_ => String::new(),
20942094
};
20952095
if !s.is_empty() {
2096-
s.push_str(" ");
2096+
s.push(' ');
20972097
}
20982098
s
20992099
};

‎compiler/rustc_infer/src/infer/lub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
5050
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
5151
ty::Covariant => self.relate(a, b),
5252
// FIXME(#41044) -- not correct, need test
53-
ty::Bivariant => Ok(a.clone()),
53+
ty::Bivariant => Ok(a),
5454
ty::Contravariant => self.fields.glb(self.a_is_expected).relate(a, b),
5555
}
5656
}

‎compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
150150
Some(mut descr) => {
151151
// Surround descr with `backticks`.
152152
descr.reserve(2);
153-
descr.insert_str(0, "`");
154-
descr.push_str("`");
153+
descr.insert(0, '`');
154+
descr.push('`');
155155
descr
156156
}
157157
None => "value".to_string(),
@@ -222,7 +222,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
222222
if self.upvars[var_index].by_ref {
223223
buf.push_str(&name);
224224
} else {
225-
buf.push_str(&format!("*{}", &name));
225+
buf.push('*');
226+
buf.push_str(&name);
226227
}
227228
} else {
228229
if autoderef {
@@ -234,7 +235,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
234235
&including_downcast,
235236
)?;
236237
} else {
237-
buf.push_str(&"*");
238+
buf.push('*');
238239
self.append_place_to_string(
239240
PlaceRef { local, projection: proj_base },
240241
buf,
@@ -272,7 +273,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
272273
autoderef,
273274
&including_downcast,
274275
)?;
275-
buf.push_str(&format!(".{}", field_name));
276+
buf.push('.');
277+
buf.push_str(&field_name);
276278
}
277279
}
278280
ProjectionElem::Index(index) => {
@@ -284,11 +286,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
284286
autoderef,
285287
&including_downcast,
286288
)?;
287-
buf.push_str("[");
289+
buf.push('[');
288290
if self.append_local_to_string(*index, buf).is_err() {
289-
buf.push_str("_");
291+
buf.push('_');
290292
}
291-
buf.push_str("]");
293+
buf.push(']');
292294
}
293295
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
294296
autoderef = true;
@@ -301,7 +303,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
301303
autoderef,
302304
&including_downcast,
303305
)?;
304-
buf.push_str(&"[..]");
306+
buf.push_str("[..]");
305307
}
306308
};
307309
}
@@ -648,7 +650,7 @@ impl UseSpans {
648650
" in closure".to_string()
649651
}
650652
}
651-
_ => "".to_string(),
653+
_ => String::new(),
652654
}
653655
}
654656

‎compiler/rustc_mir/src/borrow_check/region_infer/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ crate fn location_set_str(
417417

418418
fn region_value_str(elements: impl IntoIterator<Item = RegionElement>) -> String {
419419
let mut result = String::new();
420-
result.push_str("{");
420+
result.push('{');
421421

422422
// Set to Some(l1, l2) when we have observed all the locations
423423
// from l1..=l2 (inclusive) but not yet printed them. This
@@ -478,7 +478,7 @@ fn region_value_str(elements: impl IntoIterator<Item = RegionElement>) -> String
478478
push_location_range(&mut result, location1, location2);
479479
}
480480

481-
result.push_str("}");
481+
result.push('}');
482482

483483
return result;
484484

‎compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn collect_and_partition_mono_items<'tcx>(
382382
cgus.sort_by_key(|(name, _)| *name);
383383
cgus.dedup();
384384
for &(ref cgu_name, (linkage, _)) in cgus.iter() {
385-
output.push_str(" ");
385+
output.push(' ');
386386
output.push_str(&cgu_name.as_str());
387387

388388
let linkage_abbrev = match linkage {
@@ -399,9 +399,9 @@ fn collect_and_partition_mono_items<'tcx>(
399399
Linkage::Common => "Common",
400400
};
401401

402-
output.push_str("[");
402+
output.push('[');
403403
output.push_str(linkage_abbrev);
404-
output.push_str("]");
404+
output.push(']');
405405
}
406406
output
407407
})

‎compiler/rustc_mir/src/transform/instrument_coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
353353
if !INCLUDE_COVERAGE_STATEMENTS {
354354
continue;
355355
}
356-
format!("unreachable")
356+
String::from("unreachable")
357357
}
358358
},
359359
_ => format!("{:?}", statement),

‎compiler/rustc_mir/src/util/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fn write_scope_tree(
514514
write!(indented_decl, " as {:?}", user_ty).unwrap();
515515
}
516516
}
517-
indented_decl.push_str(";");
517+
indented_decl.push(';');
518518

519519
let local_name =
520520
if local == RETURN_PLACE { " return place".to_string() } else { String::new() };

‎compiler/rustc_save_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl<'tcx> SaveContext<'tcx> {
438438
.next()
439439
.map(|item| item.def_id);
440440
}
441-
qualname.push_str(">");
441+
qualname.push('>');
442442

443443
(qualname, trait_id, decl_id, docs, attrs)
444444
}

‎compiler/rustc_save_analysis/src/sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'hir> Sig for hir::Item<'hir> {
497497
sig.text.push_str(&bounds_to_string(bounds));
498498
}
499499
// FIXME where clause
500-
sig.text.push_str(";");
500+
sig.text.push(';');
501501

502502
Ok(sig)
503503
}

‎compiler/rustc_session/src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ impl OutputFilenames {
581581

582582
if !ext.is_empty() {
583583
if !extension.is_empty() {
584-
extension.push_str(".");
584+
extension.push('.');
585585
extension.push_str(RUST_CGU_EXT);
586-
extension.push_str(".");
586+
extension.push('.');
587587
}
588588

589589
extension.push_str(ext);

0 commit comments

Comments
 (0)
Please sign in to comment.