]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/promote_consts.rs
Various minor/cosmetic improvements to code
[rust.git] / src / librustc_mir / transform / promote_consts.rs
index e79da88a2464bf7d75d0b6815bd52bc4f316065a..7f8dfc111a4bde777ed23af81866d7a21ea859b3 100644 (file)
@@ -123,7 +123,7 @@ fn visit_local(&mut self,
             }
         } else if let TempState::Defined { ref mut uses, .. } = *temp {
             // We always allow borrows, even mutable ones, as we need
-            // to promote mutable borrows of some ZSTs e.g. `&mut []`.
+            // to promote mutable borrows of some ZSTs e.g., `&mut []`.
             let allowed_use = context.is_borrow() || context.is_nonmutating_use();
             debug!("visit_local: allowed_use={:?}", allowed_use);
             if allowed_use {
@@ -310,16 +310,11 @@ fn promote_candidate(mut self, candidate: Candidate) {
                     match statement.kind {
                         StatementKind::Assign(_, box Rvalue::Ref(_, _, ref mut place)) => {
                             // Find the underlying local for this (necessarily interior) borrow.
-                            // HACK(eddyb) using a recursive function because of mutable borrows.
-                            fn interior_base<'a, 'tcx>(place: &'a mut Place<'tcx>)
-                                                       -> &'a mut Place<'tcx> {
-                                if let Place::Projection(ref mut proj) = *place {
-                                    assert_ne!(proj.elem, ProjectionElem::Deref);
-                                    return interior_base(&mut proj.base);
-                                }
-                                place
-                            }
-                            let place = interior_base(place);
+                            let mut place = place;
+                            while let Place::Projection(ref mut proj) = *place {
+                                assert_ne!(proj.elem, ProjectionElem::Deref);
+                                place = &mut proj.base;
+                            };
 
                             let ty = place.ty(local_decls, self.tcx).to_ty(self.tcx);
                             let span = statement.source_info.span;