]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/hair/cx/mod.rs
rustc: do not depend on infcx.tables in MemCategorizationContext.
[rust.git] / src / librustc_mir / hair / cx / mod.rs
index 581a403fb6dee848861860711fca541722b9fa5b..2bb6b39966a82021fda4658c87ef462863f80167 100644 (file)
@@ -35,7 +35,9 @@
 pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'gcx, 'tcx>,
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
+    pub param_env: ty::ParamEnv<'tcx>,
     pub region_maps: Rc<RegionMaps>,
+    pub tables: &'a ty::TypeckTables<'gcx>,
 
     /// This is `Constness::Const` if we are compiling a `static`,
     /// `const`, or the body of a `const fn`.
@@ -64,7 +66,9 @@ pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, src: MirSource) -> Cx<'a, 'gcx,
         let src_id = src.item_id();
         let src_def_id = tcx.hir.local_def_id(src_id);
 
+        let param_env = tcx.param_env(src_def_id);
         let region_maps = tcx.region_maps(src_def_id);
+        let tables = tcx.typeck_tables_of(src_def_id);
 
         let attrs = tcx.hir.attrs(src_id);
 
@@ -80,7 +84,7 @@ pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, src: MirSource) -> Cx<'a, 'gcx,
         // Constants and const fn's always need overflow checks.
         check_overflow |= constness == hir::Constness::Const;
 
-        Cx { tcx, infcx, region_maps, constness, src, check_overflow }
+        Cx { tcx, infcx, param_env, region_maps, tables, constness, src, check_overflow }
     }
 }
 
@@ -169,12 +173,12 @@ pub fn all_fields(&mut self, adt_def: &ty::AdtDef, variant_index: usize) -> Vec<
     }
 
     pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
-        let ty = self.tcx.lift_to_global(&ty).unwrap_or_else(|| {
-            bug!("MIR: Cx::needs_drop({}) got \
+        let (ty, param_env) = self.tcx.lift_to_global(&(ty, self.param_env)).unwrap_or_else(|| {
+            bug!("MIR: Cx::needs_drop({:?}, {:?}) got \
                   type with inference types/regions",
-                 ty);
+                 ty, self.param_env);
         });
-        ty.needs_drop(self.tcx.global_tcx(), self.infcx.param_env)
+        ty.needs_drop(self.tcx.global_tcx(), param_env)
     }
 
     pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
@@ -182,7 +186,7 @@ pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
     }
 
     pub fn tables(&self) -> &'a ty::TypeckTables<'gcx> {
-        self.infcx.tables.expect_interned()
+        self.tables
     }
 
     pub fn check_overflow(&self) -> bool {