Skip to content

Commit 684c4e8

Browse files
committed
mir/borrowck: a few string tweaks
1 parent 3ba62dd commit 684c4e8

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
9292
mir::BorrowKind::Mut { .. } => "mut ",
9393
};
9494
let region = self.region.to_string();
95-
let region = if region.len() > 0 {
96-
format!("{} ", region)
95+
let separator = if !region.is_empty() {
96+
" "
9797
} else {
98-
region
98+
""
9999
};
100-
write!(w, "&{}{}{:?}", region, kind, self.borrowed_place)
100+
write!(w, "&{}{}{}{:?}", region, separator, kind, self.borrowed_place)
101101
}
102102
}
103103

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
579579
fn report_local_value_does_not_live_long_enough(
580580
&mut self,
581581
context: Context,
582-
name: &String,
582+
name: &str,
583583
scope_tree: &Lrc<ScopeTree>,
584584
borrow: &BorrowData<'tcx>,
585585
drop_span: Span,
@@ -1192,10 +1192,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11921192
Place::Static(ref static_) => self.describe_field_from_ty(&static_.ty, field),
11931193
Place::Projection(ref proj) => match proj.elem {
11941194
ProjectionElem::Deref => self.describe_field(&proj.base, field),
1195-
ProjectionElem::Downcast(def, variant_index) => format!(
1196-
"{}",
1197-
def.variants[variant_index].fields[field.index()].ident
1198-
),
1195+
ProjectionElem::Downcast(def, variant_index) =>
1196+
def.variants[variant_index].fields[field.index()].ident.to_string(),
11991197
ProjectionElem::Field(_, field_type) => {
12001198
self.describe_field_from_ty(&field_type, field)
12011199
}
@@ -1783,8 +1781,8 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
17831781
ty::RegionKind::RePlaceholder(ty::Placeholder { name: br, .. }),
17841782
_,
17851783
_,
1786-
) => with_highlight_region_for_bound_region(*br, counter, || format!("{}", ty)),
1787-
_ => format!("{}", ty),
1784+
) => with_highlight_region_for_bound_region(*br, counter, || ty.to_string()),
1785+
_ => ty.to_string(),
17881786
}
17891787
}
17901788

@@ -1795,9 +1793,9 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
17951793
ty::TyKind::Ref(region, _, _) => match region {
17961794
ty::RegionKind::ReLateBound(_, br)
17971795
| ty::RegionKind::RePlaceholder(ty::Placeholder { name: br, .. }) => {
1798-
with_highlight_region_for_bound_region(*br, counter, || format!("{}", region))
1796+
with_highlight_region_for_bound_region(*br, counter, || region.to_string())
17991797
}
1800-
_ => format!("{}", region),
1798+
_ => region.to_string(),
18011799
},
18021800
_ => bug!("ty for annotation of borrow region is not a reference"),
18031801
}

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
331331
_ => {
332332
let source = self.borrowed_content_source(place);
333333
self.infcx.tcx.cannot_move_out_of(
334-
span, &format!("{}", source), origin
334+
span, &source.to_string(), origin
335335
)
336336
},
337337
}
@@ -469,9 +469,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
469469
let binding_span = bind_to.source_info.span;
470470

471471
if j == 0 {
472-
err.span_label(binding_span, format!("data moved here"));
472+
err.span_label(binding_span, "data moved here");
473473
} else {
474-
err.span_label(binding_span, format!("...and here"));
474+
err.span_label(binding_span, "...and here");
475475
}
476476

477477
if binds_to.len() == 1 {

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
504504
);
505505

506506
let extra = if found {
507-
String::from("")
507+
String::new()
508508
} else {
509509
format!(", but it is not implemented for `{}`",
510510
substs.type_at(0))
@@ -583,7 +583,7 @@ fn suggest_ampmut<'cx, 'gcx, 'tcx>(
583583
let ty = &src[ws_pos..];
584584
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty));
585585
} else if src.starts_with('&') {
586-
let borrowed_expr = src[1..].to_string();
586+
let borrowed_expr = &src[1..];
587587
return (assignment_rhs_span, format!("&mut {}", borrowed_expr));
588588
}
589589
}

0 commit comments

Comments
 (0)