about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2019-05-28 16:47:59 +0200
committerSantiago Pastorino <spastorino@gmail.com>2019-05-28 18:30:27 +0200
commitbb94fc00695be648f62751e8f393e11644d938ae (patch)
tree21b0a7fe839cee808312617f15a12828319e8746
parent1b86bd73cd5e8e463f50e5c53968125d0ab4e1f0 (diff)
downloadrust-bb94fc00695be648f62751e8f393e11644d938ae.tar.gz
rust-bb94fc00695be648f62751e8f393e11644d938ae.zip
Use closure to avoid self.describe_place(...).unwrap_or_else(...) repetition
-rw-r--r--src/librustc_mir/borrow_check/conflict_errors.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs
index 58adc24b809..5c5d495466c 100644
--- a/src/librustc_mir/borrow_check/conflict_errors.rs
+++ b/src/librustc_mir/borrow_check/conflict_errors.rs
@@ -599,6 +599,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             let ty = place.ty(self.mir, self.infcx.tcx).ty;
             ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
         };
+        let describe_place = |place| self.describe_place(place).unwrap_or_else(|| "_".to_owned());
 
         // Start with an empty tuple, so we can use the functions on `Option` to reduce some
         // code duplication (particularly around returning an empty description in the failure
@@ -633,19 +634,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                     if let ProjectionElem::Field(field, _) = elem {
                         if let Some(union_ty) = union_ty(base) {
                             if field != target_field && base == target_base {
-                                let desc_base =
-                                    self.describe_place(base).unwrap_or_else(|| "_".to_owned());
-                                let desc_first = self
-                                    .describe_place(first_borrowed_place)
-                                    .unwrap_or_else(|| "_".to_owned());
-                                let desc_second = self
-                                    .describe_place(second_borrowed_place)
-                                    .unwrap_or_else(|| "_".to_owned());
-
                                 return Some((
-                                    desc_base,
-                                    desc_first,
-                                    desc_second,
+                                    describe_place(base),
+                                    describe_place(first_borrowed_place),
+                                    describe_place(second_borrowed_place),
                                     union_ty.to_string(),
                                 ));
                             }
@@ -659,9 +651,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             .unwrap_or_else(|| {
                 // If we didn't find a field access into a union, or both places match, then
                 // only return the description of the first place.
-                let desc_place = self.describe_place(first_borrowed_place)
-                    .unwrap_or_else(|| "_".to_owned());
-                (desc_place, "".to_string(), "".to_string(), "".to_string())
+                (
+                    describe_place(first_borrowed_place),
+                    "".to_string(),
+                    "".to_string(),
+                    "".to_string(),
+                )
             })
     }