Skip to content

Commit bb94fc0

Browse files
committed
Use closure to avoid self.describe_place(...).unwrap_or_else(...) repetition
1 parent 1b86bd7 commit bb94fc0

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/librustc_mir/borrow_check/conflict_errors.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
599599
let ty = place.ty(self.mir, self.infcx.tcx).ty;
600600
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
601601
};
602+
let describe_place = |place| self.describe_place(place).unwrap_or_else(|| "_".to_owned());
602603

603604
// Start with an empty tuple, so we can use the functions on `Option` to reduce some
604605
// code duplication (particularly around returning an empty description in the failure
@@ -633,19 +634,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
633634
if let ProjectionElem::Field(field, _) = elem {
634635
if let Some(union_ty) = union_ty(base) {
635636
if field != target_field && base == target_base {
636-
let desc_base =
637-
self.describe_place(base).unwrap_or_else(|| "_".to_owned());
638-
let desc_first = self
639-
.describe_place(first_borrowed_place)
640-
.unwrap_or_else(|| "_".to_owned());
641-
let desc_second = self
642-
.describe_place(second_borrowed_place)
643-
.unwrap_or_else(|| "_".to_owned());
644-
645637
return Some((
646-
desc_base,
647-
desc_first,
648-
desc_second,
638+
describe_place(base),
639+
describe_place(first_borrowed_place),
640+
describe_place(second_borrowed_place),
649641
union_ty.to_string(),
650642
));
651643
}
@@ -659,9 +651,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
659651
.unwrap_or_else(|| {
660652
// If we didn't find a field access into a union, or both places match, then
661653
// only return the description of the first place.
662-
let desc_place = self.describe_place(first_borrowed_place)
663-
.unwrap_or_else(|| "_".to_owned());
664-
(desc_place, "".to_string(), "".to_string(), "".to_string())
654+
(
655+
describe_place(first_borrowed_place),
656+
"".to_string(),
657+
"".to_string(),
658+
"".to_string(),
659+
)
665660
})
666661
}
667662

0 commit comments

Comments
 (0)