about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Daniel Faria <Nashenas88@users.noreply.github.com>2019-11-06 00:04:53 -0500
committerPaul Daniel Faria <Nashenas88@users.noreply.github.com>2019-12-02 08:38:16 -0500
commit595d161d36b5126e75840c29ce0413a07feebd02 (patch)
tree0d145a73b39ad9e3c9ce028503ff4c996b585fdf
parentc42bdb8c7465389a4d71d88ff8d910d6307be9ba (diff)
downloadrust-595d161d36b5126e75840c29ce0413a07feebd02.tar.gz
rust-595d161d36b5126e75840c29ce0413a07feebd02.zip
Remove BodyCache.body and rely on Deref as much as possible for ReadOnlyBodyCache
-rw-r--r--src/librustc/mir/cache.rs22
-rw-r--r--src/librustc/mir/visit.rs12
-rw-r--r--src/librustc/ty/mod.rs2
-rw-r--r--src/librustc_codegen_ssa/mir/analyze.rs2
-rw-r--r--src/librustc_codegen_ssa/mir/block.rs9
-rw-r--r--src/librustc_codegen_ssa/mir/mod.rs2
-rw-r--r--src/librustc_codegen_ssa/mir/place.rs5
-rw-r--r--src/librustc_codegen_ssa/mir/rvalue.rs6
-rw-r--r--src/librustc_mir/borrow_check/borrow_set.rs2
-rw-r--r--src/librustc_mir/borrow_check/conflict_errors.rs10
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs6
-rw-r--r--src/librustc_mir/borrow_check/mod.rs8
-rw-r--r--src/librustc_mir/borrow_check/move_errors.rs8
-rw-r--r--src/librustc_mir/borrow_check/mutability_errors.rs8
-rw-r--r--src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs2
-rw-r--r--src/librustc_mir/borrow_check/nll/invalidation.rs2
-rw-r--r--src/librustc_mir/borrow_check/nll/mod.rs14
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/mod.rs1
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs6
-rw-r--r--src/librustc_mir/borrow_check/prefixes.rs8
-rw-r--r--src/librustc_mir/monomorphize/collector.rs3
-rw-r--r--src/librustc_mir/shim.rs8
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs2
-rw-r--r--src/librustc_mir/transform/generator.rs4
-rw-r--r--src/librustc_mir/transform/inline.rs6
-rw-r--r--src/librustc_mir/transform/remove_noop_landing_pads.rs2
-rw-r--r--src/librustc_mir/transform/rustc_peek.rs8
-rw-r--r--src/librustc_mir/transform/simplify.rs4
-rw-r--r--src/librustc_mir/transform/uniform_array_move_out.rs2
-rw-r--r--src/librustc_mir/util/liveness.rs2
30 files changed, 89 insertions, 87 deletions
diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs
index 204b3d9f7e3..e7ca7d6a95f 100644
--- a/src/librustc/mir/cache.rs
+++ b/src/librustc/mir/cache.rs
@@ -2,7 +2,7 @@ use rustc_index::vec::IndexVec;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
 use crate::ich::StableHashingContext;
-use crate::mir::{BasicBlock, BasicBlockData, Body, LocalDecls, Location, Successors};
+use crate::mir::{BasicBlock, BasicBlockData, Body, HasLocalDecls, LocalDecls, Location, Successors};
 use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
 use rustc_data_structures::graph::dominators::{dominators, Dominators};
 use std::iter;
@@ -181,14 +181,6 @@ impl BodyCache<'tcx> {
         ReadOnlyBodyCache::new(&self.cache, &self.body)
     }
 
-    pub fn body(&self) -> &Body<'tcx> {
-        &self.body
-    }
-
-    pub fn body_mut(&mut self) -> &mut Body<'tcx> {
-        &mut self.body
-    }
-
     pub fn cache(&self) -> &Cache { &self.cache }
 
     pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
@@ -231,6 +223,12 @@ impl<'tcx> DerefMut for BodyCache<'tcx> {
     }
 }
 
+impl<'tcx> HasLocalDecls<'tcx> for BodyCache<'tcx> {
+    fn local_decls(&self) -> &LocalDecls<'tcx> {
+        &self.body.local_decls
+    }
+}
+
 #[derive(Copy, Clone, Debug)]
 pub struct ReadOnlyBodyCache<'a, 'tcx> {
     cache: &'a Cache,
@@ -349,6 +347,12 @@ impl Index<BasicBlock> for ReadOnlyBodyCache<'a, 'tcx> {
     }
 }
 
+impl<'a, 'tcx> HasLocalDecls<'tcx> for ReadOnlyBodyCache<'a, 'tcx> {
+    fn local_decls(&self) -> &LocalDecls<'tcx> {
+        &self.body.local_decls
+    }
+}
+
 CloneTypeFoldableAndLiftImpls! {
     Cache,
 }
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs
index 68694f1b717..18776778ebb 100644
--- a/src/librustc/mir/visit.rs
+++ b/src/librustc/mir/visit.rs
@@ -254,14 +254,10 @@ macro_rules! make_mir_visitor {
 
             fn super_body(
                 &mut self,
-                body_cache: body_cache_type!($($mutability)? '_, 'tcx)
+                $($mutability)? body_cache: body_cache_type!($($mutability)? '_, 'tcx)
             ) {
-                macro_rules! body {
-                    (mut) => (body_cache.body_mut());
-                    () => (body_cache.body());
-                }
-                let span = body_cache.body().span;
-                if let Some(yield_ty) = &$($mutability)? body!($($mutability)?).yield_ty {
+                let span = body_cache.span;
+                if let Some(yield_ty) = &$($mutability)? body_cache.yield_ty {
                     self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
                         span,
                         scope: OUTERMOST_SOURCE_SCOPE,
@@ -279,7 +275,7 @@ macro_rules! make_mir_visitor {
                     self.visit_basic_block_data(bb, data);
                 }
 
-                let body = body!($($mutability)?);
+                let body: & $($mutability)? Body<'_> = & $($mutability)? body_cache;
                 for scope in &$($mutability)? body.source_scopes {
                     self.visit_source_scope_data(scope);
                 }
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index cf9fd401e7b..c9a934e9ebd 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -3023,7 +3023,7 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> {
-        self.optimized_mir(def_id).body().generator_layout.as_ref().unwrap()
+        self.optimized_mir(def_id).generator_layout.as_ref().unwrap()
     }
 
     /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs
index d6fa67b0533..782c0f7e139 100644
--- a/src/librustc_codegen_ssa/mir/analyze.rs
+++ b/src/librustc_codegen_ssa/mir/analyze.rs
@@ -131,7 +131,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
             };
             if is_consume {
                 let base_ty =
-                    mir::Place::ty_from(place_ref.base, proj_base, self.fx.mir.body(), cx.tcx());
+                    mir::Place::ty_from(place_ref.base, proj_base, &self.fx.mir, cx.tcx());
                 let base_ty = self.fx.monomorphize(&base_ty);
 
                 // ZSTs don't require any actual memory access.
diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs
index 2d41c8426de..0920de7d903 100644
--- a/src/librustc_codegen_ssa/mir/block.rs
+++ b/src/librustc_codegen_ssa/mir/block.rs
@@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         target: mir::BasicBlock,
         unwind: Option<mir::BasicBlock>,
     ) {
-        let ty = location.ty(self.mir.body(), bx.tcx()).ty;
+        let ty = location.ty(&self.mir, bx.tcx()).ty;
         let ty = self.monomorphize(&ty);
         let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
 
@@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 
         let extra_args = &args[sig.inputs().len()..];
         let extra_args = extra_args.iter().map(|op_arg| {
-            let op_ty = op_arg.ty(self.mir.body(), bx.tcx());
+            let op_ty = op_arg.ty(&self.mir, bx.tcx());
             self.monomorphize(&op_ty)
         }).collect::<Vec<_>>();
 
@@ -569,7 +569,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 // a NOP
                 let target = destination.as_ref().unwrap().1;
                 helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
-                helper.funclet_br(self, &mut bx, destination.as_ref().unwrap().1)
+                helper.funclet_br(self, &mut bx, target)
             }
             return;
         }
@@ -791,7 +791,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         bb: mir::BasicBlock,
     ) {
         let mut bx = self.build_block(bb);
-        let data = &self.mir.body()[bb];
+        let mir = self.mir;
+        let data = &mir[bb];
 
         debug!("codegen_block({:?}={:?})", bb, data);
 
diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs
index 9549749f512..9374c829e4f 100644
--- a/src/librustc_codegen_ssa/mir/mod.rs
+++ b/src/librustc_codegen_ssa/mir/mod.rs
@@ -156,7 +156,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
         }).collect();
 
     let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs);
-    let mir_body = mir.body();
+    let mir_body: &Body<'_> = &mir;
     let mut fx = FunctionCx {
         instance,
         mir,
diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs
index 0790526e9f9..5ea08edd035 100644
--- a/src/librustc_codegen_ssa/mir/place.rs
+++ b/src/librustc_codegen_ssa/mir/place.rs
@@ -594,8 +594,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         let place_ty = mir::Place::ty_from(
             place_ref.base,
             place_ref.projection,
-            self.mir.body(),
-            tcx);
+            &self.mir,
+            tcx,
+        );
         self.monomorphize(&place_ty.ty)
     }
 }
diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs
index fb5fc561b08..fa157a0c35f 100644
--- a/src/librustc_codegen_ssa/mir/rvalue.rs
+++ b/src/librustc_codegen_ssa/mir/rvalue.rs
@@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             }
 
             mir::Rvalue::Discriminant(ref place) => {
-                let discr_ty = rvalue.ty(self.mir.body(), bx.tcx());
+                let discr_ty = rvalue.ty(&self.mir, bx.tcx());
                 let discr =  self.codegen_place(&mut bx, &place.as_ref())
                     .codegen_get_discr(&mut bx, discr_ty);
                 (bx, OperandRef {
@@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             mir::Rvalue::Aggregate(..) => {
                 // According to `rvalue_creates_operand`, only ZST
                 // aggregate rvalues are allowed to be operands.
-                let ty = rvalue.ty(self.mir.body(), self.cx.tcx());
+                let ty = rvalue.ty(&self.mir, self.cx.tcx());
                 let operand = OperandRef::new_zst(
                     &mut bx,
                     self.cx.layout_of(self.monomorphize(&ty)),
@@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 true,
             mir::Rvalue::Repeat(..) |
             mir::Rvalue::Aggregate(..) => {
-                let ty = rvalue.ty(self.mir.body(), self.cx.tcx());
+                let ty = rvalue.ty(&self.mir, self.cx.tcx());
                 let ty = self.monomorphize(&ty);
                 self.cx.spanned_layout_of(ty, span).is_zst()
             }
diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs
index 1553131c5d6..aaf067a5361 100644
--- a/src/librustc_mir/borrow_check/borrow_set.rs
+++ b/src/librustc_mir/borrow_check/borrow_set.rs
@@ -130,7 +130,7 @@ impl<'tcx> BorrowSet<'tcx> {
     ) -> Self {
         let mut visitor = GatherBorrows {
             tcx,
-            body: body_cache.body(),
+            body: &body_cache,
             idx_vec: IndexVec::new(),
             location_map: Default::default(),
             activation_map: Default::default(),
diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs
index 7f2d6a68d02..9dac6d70dff 100644
--- a/src/librustc_mir/borrow_check/conflict_errors.rs
+++ b/src/librustc_mir/borrow_check/conflict_errors.rs
@@ -208,7 +208,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
             let ty = Place::ty_from(
                 used_place.base,
                 used_place.projection,
-                self.body_cache.body(),
+                &self.body_cache,
                 self.infcx.tcx
             ).ty;
             let needs_note = match ty.kind {
@@ -225,7 +225,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                 let mpi = self.move_data.moves[move_out_indices[0]].path;
                 let place = &self.move_data.move_paths[mpi].place;
 
-                let ty = place.ty(self.body_cache.body(), self.infcx.tcx).ty;
+                let ty = place.ty(&self.body_cache, self.infcx.tcx).ty;
                 let opt_name =
                     self.describe_place_with_options(place.as_ref(), IncludingDowncast(true));
                 let note_msg = match opt_name {
@@ -625,7 +625,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
             let ty = Place::ty_from(
                 place_base,
                 place_projection,
-                self.body_cache.body(),
+                &self.body_cache,
                 self.infcx.tcx
             ).ty;
             ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
@@ -1635,7 +1635,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                                 Place::ty_from(
                                     &place.base,
                                     proj_base,
-                                    self.body_cache.body(),
+                                    &self.body_cache,
                                     tcx
                                 ).ty.is_box(),
                                 "Drop of value behind a reference or raw pointer"
@@ -1648,7 +1648,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                         let base_ty = Place::ty_from(
                             &place.base,
                             proj_base,
-                            self.body_cache.body(),
+                            &self.body_cache,
                             tcx
                         ).ty;
                         match base_ty.kind {
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index 3b394f853a7..3515c4bfe09 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                     let base_ty = Place::ty_from(
                         place.base,
                         place.projection,
-                        self.body_cache.body(),
+                        &self.body_cache,
                         self.infcx.tcx).ty;
                     self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
                 }
@@ -502,7 +502,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                         ..
                     }) = bbd.terminator {
                         if let Some(source) = BorrowedContentSource::from_call(
-                            func.ty(self.body_cache.body(), tcx),
+                            func.ty(&self.body_cache, tcx),
                             tcx
                         ) {
                             return source;
@@ -519,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         let base_ty = Place::ty_from(
             deref_base.base,
             deref_base.projection,
-            self.body_cache.body(),
+            &self.body_cache,
             tcx
         ).ty;
         if base_ty.is_unsafe_ptr() {
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 1ff26acd361..a6fc3e0b21a 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -646,7 +646,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
                 let tcx = self.infcx.tcx;
 
                 // Compute the type with accurate region information.
-                let drop_place_ty = drop_place.ty(self.body_cache.body(), self.infcx.tcx);
+                let drop_place_ty = drop_place.ty(&self.body_cache, self.infcx.tcx);
 
                 // Erase the regions.
                 let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
@@ -990,7 +990,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
 
         let mut error_reported = false;
         let tcx = self.infcx.tcx;
-        let body = self.body_cache.body();
+        let body_cache = self.body_cache;
+        let body: &Body<'_> = &body_cache;
         let param_env = self.param_env;
         let location_table = self.location_table.start_index(location);
         let borrow_set = self.borrow_set.clone();
@@ -1341,7 +1342,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                             _ => bug!("temporary initialized in arguments"),
                         };
 
-                        let bbd = &self.body_cache.body()[loc.block];
+                        let body_cache = self.body_cache;
+                        let bbd = &body_cache[loc.block];
                         let stmt = &bbd.statements[loc.statement_index];
                         debug!("temporary assigned in: stmt={:?}", stmt);
 
diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs
index 5907da09c67..f5ef37bb0f4 100644
--- a/src/librustc_mir/borrow_check/move_errors.rs
+++ b/src/librustc_mir/borrow_check/move_errors.rs
@@ -300,7 +300,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
         // Inspect the type of the content behind the
         // borrow to provide feedback about why this
         // was a move rather than a copy.
-        let ty = deref_target_place.ty(self.body_cache.body(), self.infcx.tcx).ty;
+        let ty = deref_target_place.ty(&self.body_cache, self.infcx.tcx).ty;
         let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All)
             .find_map(|p| self.is_upvar_field_projection(p));
 
@@ -411,7 +411,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
         };
         let move_ty = format!(
             "{:?}",
-            move_place.ty(self.body_cache.body(), self.infcx.tcx).ty,
+            move_place.ty(&self.body_cache, self.infcx.tcx).ty,
         );
         if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
             let is_option = move_ty.starts_with("std::option::Option");
@@ -454,7 +454,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                 }
 
                 if binds_to.is_empty() {
-                    let place_ty = move_from.ty(self.body_cache.body(), self.infcx.tcx).ty;
+                    let place_ty = move_from.ty(&self.body_cache, self.infcx.tcx).ty;
                     let place_desc = match self.describe_place(move_from.as_ref()) {
                         Some(desc) => format!("`{}`", desc),
                         None => format!("value"),
@@ -482,7 +482,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
             // No binding. Nothing to suggest.
             GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
                 let span = use_spans.var_or_use();
-                let place_ty = original_path.ty(self.body_cache.body(), self.infcx.tcx).ty;
+                let place_ty = original_path.ty(&self.body_cache, self.infcx.tcx).ty;
                 let place_desc = match self.describe_place(original_path.as_ref()) {
                     Some(desc) => format!("`{}`", desc),
                     None => format!("value"),
diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs
index 0ec72150d97..bae5d2e1742 100644
--- a/src/librustc_mir/borrow_check/mutability_errors.rs
+++ b/src/librustc_mir/borrow_check/mutability_errors.rs
@@ -64,7 +64,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                     Place::ty_from(
                         &the_place_err.base,
                         proj_base,
-                        self.body_cache.body(),
+                        &self.body_cache,
                         self.infcx.tcx
                     ).ty));
 
@@ -115,7 +115,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                         Place::ty_from(
                             the_place_err.base,
                             the_place_err.projection,
-                            self.body_cache.body(),
+                            &self.body_cache,
                             self.infcx.tcx
                         )
                         .ty
@@ -229,7 +229,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
 
                 if let Some((span, message)) = annotate_struct_field(
                     self.infcx.tcx,
-                    Place::ty_from(base, proj_base, self.body_cache.body(), self.infcx.tcx).ty,
+                    Place::ty_from(base, proj_base, &self.body_cache, self.infcx.tcx).ty,
                     field,
                 ) {
                     err.span_suggestion(
@@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                 projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
             } => {
                 debug_assert!(is_closure_or_generator(
-                    Place::ty_from(base, proj_base, self.body_cache.body(), self.infcx.tcx).ty
+                    Place::ty_from(base, proj_base, &self.body_cache, self.infcx.tcx).ty
                 ));
 
                 err.span_label(span, format!("cannot {ACT}", ACT = act));
diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
index 4097bfeeb35..1e07f354b83 100644
--- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
@@ -237,7 +237,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         );
 
         let regioncx = &self.nonlexical_regioncx;
-        let body = self.body_cache.body();
+        let body: &Body<'_> = &self.body_cache;
         let tcx = self.infcx.tcx;
 
         let borrow_region_vid = borrow.region;
diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs
index 8d5466e545d..a2929fe4747 100644
--- a/src/librustc_mir/borrow_check/nll/invalidation.rs
+++ b/src/librustc_mir/borrow_check/nll/invalidation.rs
@@ -38,7 +38,7 @@ pub(super) fn generate_invalidates<'tcx>(
             param_env,
             tcx,
             location_table,
-            body: body_cache.body(),
+            body: &body_cache,
             dominators,
         };
         ig.visit_body(body_cache);
diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs
index 519b59304b7..ff28a27911b 100644
--- a/src/librustc_mir/borrow_check/nll/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/mod.rs
@@ -181,7 +181,8 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
 
     let universal_regions = Rc::new(universal_regions);
 
-    let elements = &Rc::new(RegionValueElements::new(body_cache.body()));
+    let elements
+        = &Rc::new(RegionValueElements::new(&body_cache));
 
     // Run the MIR type-checker.
     let MirTypeckResults {
@@ -206,7 +207,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
         all_facts
             .universal_region
             .extend(universal_regions.universal_regions());
-        populate_polonius_move_facts(all_facts, move_data, location_table, body_cache.body());
+        populate_polonius_move_facts(all_facts, move_data, location_table, &body_cache);
     }
 
     // Create the region inference context, taking ownership of the
@@ -230,7 +231,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
         &mut liveness_constraints,
         &mut all_facts,
         location_table,
-        body_cache.body(),
+        &body_cache,
         borrow_set,
     );
 
@@ -239,7 +240,6 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
         universal_regions,
         placeholder_indices,
         universal_region_relations,
-        body_cache.body(),
         outlives_constraints,
         member_constraints,
         closure_bounds_mapping,
@@ -284,14 +284,14 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
 
     // Solve the region constraints.
     let closure_region_requirements =
-        regioncx.solve(infcx, body_cache.body(), local_names, upvars, def_id, errors_buffer);
+        regioncx.solve(infcx, &body_cache, local_names, upvars, def_id, errors_buffer);
 
     // Dump MIR results into a file, if that is enabled. This let us
     // write unit-tests, as well as helping with debugging.
     dump_mir_results(
         infcx,
         MirSource::item(def_id),
-        body_cache.body(),
+        &body_cache,
         &regioncx,
         &closure_region_requirements,
     );
@@ -300,7 +300,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
     // information
     dump_annotation(
         infcx,
-        body_cache.body(),
+        &body_cache,
         def_id,
         &regioncx,
         &closure_region_requirements,
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
index d44e85fa790..bd9e97e5b63 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
@@ -239,7 +239,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         universal_regions: Rc<UniversalRegions<'tcx>>,
         placeholder_indices: Rc<PlaceholderIndices>,
         universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
-        _body: &Body<'tcx>,
         outlives_constraints: OutlivesConstraintSet,
         member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
         closure_bounds_mapping: FxHashMap<
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index 7200f8d8ae5..5190e0f939f 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -169,7 +169,7 @@ pub(crate) fn type_check<'tcx>(
         &universal_region_relations,
         |mut cx| {
             cx.equate_inputs_and_outputs(
-                body_cache.body(),
+                &body_cache,
                 universal_regions,
                 &normalized_inputs_and_output);
             liveness::generate(
@@ -201,7 +201,7 @@ fn type_check_internal<'a, 'tcx, R>(
     borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
     universal_region_relations: &'a UniversalRegionRelations<'tcx>,
     mut extra: impl FnMut(&mut TypeChecker<'a, 'tcx>) -> R,
-) -> R where {
+) -> R {
     let mut checker = TypeChecker::new(
         infcx,
         body_cache.body(),
@@ -220,7 +220,7 @@ fn type_check_internal<'a, 'tcx, R>(
 
     if !errors_reported {
         // if verifier failed, don't do further checks to avoid ICEs
-        checker.typeck_mir(body_cache.body());
+        checker.typeck_mir(&body_cache);
     }
 
     extra(&mut checker)
diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs
index ccd6d285a7b..82763df7492 100644
--- a/src/librustc_mir/borrow_check/prefixes.rs
+++ b/src/librustc_mir/borrow_check/prefixes.rs
@@ -11,7 +11,7 @@ use super::MirBorrowckCtxt;
 
 use rustc::hir;
 use rustc::ty::{self, TyCtxt};
-use rustc::mir::{Body, Place, PlaceBase, PlaceRef, ProjectionElem};
+use rustc::mir::{Place, PlaceBase, PlaceRef, ProjectionElem, ReadOnlyBodyCache};
 
 pub trait IsPrefixOf<'cx, 'tcx> {
     fn is_prefix_of(&self, other: PlaceRef<'cx, 'tcx>) -> bool;
@@ -26,7 +26,7 @@ impl<'cx, 'tcx> IsPrefixOf<'cx, 'tcx> for PlaceRef<'cx, 'tcx> {
 }
 
 pub(super) struct Prefixes<'cx, 'tcx> {
-    body: &'cx Body<'tcx>,
+    body_cache: ReadOnlyBodyCache<'cx, 'tcx>,
     tcx: TyCtxt<'tcx>,
     kind: PrefixSet,
     next: Option<PlaceRef<'cx, 'tcx>>,
@@ -56,7 +56,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         Prefixes {
             next: Some(place_ref),
             kind,
-            body: self.body_cache.body(),
+            body_cache: self.body_cache,
             tcx: self.infcx.tcx,
         }
     }
@@ -143,7 +143,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
                     // derefs, except we stop at the deref of a shared
                     // reference.
 
-                    let ty = Place::ty_from(cursor.base, proj_base, self.body, self.tcx).ty;
+                    let ty = Place::ty_from(cursor.base, proj_base, &self.body_cache, self.tcx).ty;
                     match ty.kind {
                         ty::RawPtr(_) |
                         ty::Ref(
diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs
index ecfbe529b95..67de4ce168c 100644
--- a/src/librustc_mir/monomorphize/collector.rs
+++ b/src/librustc_mir/monomorphize/collector.rs
@@ -1249,11 +1249,10 @@ fn collect_neighbours<'tcx>(
 ) {
     debug!("collect_neighbours: {:?}", instance.def_id());
     let body_cache = tcx.instance_mir(instance.def);
-    let body = body_cache.body();
 
     MirNeighborCollector {
         tcx,
-        body: &body,
+        body: &body_cache,
         output,
         param_substs: instance.substs,
     }.visit_body(body_cache);
diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs
index 9b54c66e1e5..43600d6a5d8 100644
--- a/src/librustc_mir/shim.rs
+++ b/src/librustc_mir/shim.rs
@@ -113,7 +113,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
             bug!("creating shims from intrinsics ({:?}) is unsupported", instance)
         }
     };
-    debug!("make_shim({:?}) = untransformed {:?}", instance, result.body());
+    debug!("make_shim({:?}) = untransformed {:?}", instance, result);
 
     run_passes(tcx, &mut result, instance, None, MirPhase::Const, &[
         &add_moves_for_packed_drops::AddMovesForPackedDrops,
@@ -123,7 +123,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
         &add_call_guards::CriticalCallEdges,
     ]);
 
-    debug!("make_shim({:?}) = {:?}", instance, result.body());
+    debug!("make_shim({:?}) = {:?}", instance, result);
 
     result.ensure_predecessors();
     tcx.arena.alloc(result)
@@ -220,8 +220,8 @@ fn build_drop_shim<'tcx>(
         let patch = {
             let param_env = tcx.param_env(def_id).with_reveal_all();
             let mut elaborator = DropShimElaborator {
-                body: body_cache.body(),
-                patch: MirPatch::new(body_cache.body()),
+                body: &body_cache,
+                patch: MirPatch::new(&body_cache),
                 tcx,
                 param_env
             };
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index d2d4eef1164..9e314dbc6e8 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -529,7 +529,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
     };
     let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body_cache, tcx, param_env);
     let mut cache = body_cache.cache().clone();
-    let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body_cache.body());
+    let read_only_cache = ReadOnlyBodyCache::from_external_cache(&mut cache, body_cache);
     checker.visit_body(read_only_cache);
 
     check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs
index c79178dcac7..f9b8b3d6aec 100644
--- a/src/librustc_mir/transform/generator.rs
+++ b/src/librustc_mir/transform/generator.rs
@@ -487,7 +487,7 @@ fn locals_live_across_suspend_points(
 ) -> LivenessInfo {
     let dead_unwinds = BitSet::new_empty(body_cache.basic_blocks().len());
     let def_id = source.def_id();
-    let body = body_cache.body();
+    let body: &Body<'_> = &body_cache;
 
     // Calculate when MIR locals have live storage. This gives us an upper bound of their
     // lifetimes.
@@ -932,7 +932,7 @@ fn create_generator_drop_shim<'tcx>(
 ) -> BodyCache<'tcx> {
     let mut body_cache = body_cache.clone();
 
-    let source_info = source_info(body_cache.body());
+    let source_info = source_info(&body_cache);
 
     let mut cases = create_cases(&mut body_cache, transform, |point| point.drop);
 
diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs
index 6721982e846..922b0937065 100644
--- a/src/librustc_mir/transform/inline.rs
+++ b/src/librustc_mir/transform/inline.rs
@@ -448,7 +448,7 @@ impl Inliner<'tcx> {
                         BorrowKind::Mut { allow_two_phase_borrow: false },
                         destination.0);
 
-                    let ty = dest.ty(caller_body.body(), self.tcx);
+                    let ty = dest.ty(caller_body, self.tcx);
 
                     let temp = LocalDecl::new_temp(ty, callsite.location.span);
 
@@ -553,7 +553,7 @@ impl Inliner<'tcx> {
             assert!(args.next().is_none());
 
             let tuple = Place::from(tuple);
-            let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body_cache.body(), tcx).ty.kind {
+            let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body_cache, tcx).ty.kind {
                 s
             } else {
                 bug!("Closure arguments are not passed as a tuple");
@@ -608,7 +608,7 @@ impl Inliner<'tcx> {
         // Otherwise, create a temporary for the arg
         let arg = Rvalue::Use(arg);
 
-        let ty = arg.ty(caller_body_cache.body(), self.tcx);
+        let ty = arg.ty(caller_body_cache, self.tcx);
 
         let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span);
         let arg_tmp = caller_body_cache.local_decls.push(arg_tmp);
diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs
index 3a7d7d17f06..386e04bc083 100644
--- a/src/librustc_mir/transform/remove_noop_landing_pads.rs
+++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs
@@ -13,7 +13,7 @@ pub fn remove_noop_landing_pads<'tcx>(tcx: TyCtxt<'tcx>, body_cache: &mut BodyCa
     if tcx.sess.no_landing_pads() {
         return
     }
-    debug!("remove_noop_landing_pads({:?})", body_cache.body());
+    debug!("remove_noop_landing_pads({:?})", body_cache);
 
     RemoveNoopLandingPads.remove_nop_landing_pads(body_cache)
 }
diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs
index 6e877d2fb74..de8a8ceed31 100644
--- a/src/librustc_mir/transform/rustc_peek.rs
+++ b/src/librustc_mir/transform/rustc_peek.rs
@@ -58,15 +58,15 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
                         |_, i| DebugFormatted::new(&i));
 
         if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_init).is_some() {
-            sanity_check_via_rustc_peek(tcx, body_cache.body(), def_id, &attributes, &flow_inits);
+            sanity_check_via_rustc_peek(tcx, body_cache, def_id, &attributes, &flow_inits);
         }
         if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_uninit).is_some() {
-            sanity_check_via_rustc_peek(tcx, body_cache.body(), def_id, &attributes, &flow_uninits);
+            sanity_check_via_rustc_peek(tcx, body_cache, def_id, &attributes, &flow_uninits);
         }
         if has_rustc_mir_with(&attributes, sym::rustc_peek_definite_init).is_some() {
             sanity_check_via_rustc_peek(
                 tcx,
-                body_cache.body(),
+                body_cache,
                 def_id,
                 &attributes,
                 &flow_def_inits);
@@ -74,7 +74,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
         if has_rustc_mir_with(&attributes, sym::rustc_peek_indirectly_mutable).is_some() {
             sanity_check_via_rustc_peek(
                 tcx,
-                body_cache.body(),
+                body_cache,
                 def_id,
                 &attributes,
                 &flow_indirectly_mut);
diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs
index 949059f19ae..3057d67f9ef 100644
--- a/src/librustc_mir/transform/simplify.rs
+++ b/src/librustc_mir/transform/simplify.rs
@@ -59,7 +59,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
     fn run_pass(
         &self, _tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body_cache: &mut BodyCache<'tcx>
     ) {
-        debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body_cache.body());
+        debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body_cache);
         simplify_cfg(body_cache);
     }
 }
@@ -264,7 +264,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
 
 pub fn remove_dead_blocks(body_cache: &mut BodyCache<'_>) {
     let mut seen = BitSet::new_empty(body_cache.basic_blocks().len());
-    for (bb, _) in traversal::preorder(body_cache.body()) {
+    for (bb, _) in traversal::preorder(body_cache) {
         seen.insert(bb.index());
     }
 
diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs
index 62a2f269fac..d4d24347f72 100644
--- a/src/librustc_mir/transform/uniform_array_move_out.rs
+++ b/src/librustc_mir/transform/uniform_array_move_out.rs
@@ -223,7 +223,7 @@ impl<'tcx> MirPass<'tcx> for RestoreSubsliceArrayMoveOut<'tcx> {
                             let src_ty = Place::ty_from(
                                 src_place.base,
                                 src_place.projection,
-                                body_cache.body(),
+                                body_cache,
                                 tcx
                             ).ty;
                             if let ty::Array(_, ref size_o) = src_ty.kind {
diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs
index 1773dbd2e34..56a31337a08 100644
--- a/src/librustc_mir/util/liveness.rs
+++ b/src/librustc_mir/util/liveness.rs
@@ -85,7 +85,7 @@ pub fn liveness_of_locals(
     // any benefits. Benchmark this and find out.
     let mut dirty_queue: WorkQueue<BasicBlock>
         = WorkQueue::with_none(body_cache.basic_blocks().len());
-    for (bb, _) in traversal::postorder(body_cache.body()) {
+    for (bb, _) in traversal::postorder(&body_cache) {
         dirty_queue.insert(bb);
     }