]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/inline.rs
Move def_id out add substsref
[rust.git] / src / librustc_mir / transform / inline.rs
index bc7bd39be488e35684356634eb789a289607f23c..533e08f5e1fd3cf40c446a4b8e61ae8d6ec16f7a 100644 (file)
@@ -37,8 +37,8 @@ struct CallSite<'tcx> {
     location: SourceInfo,
 }
 
-impl MirPass for Inline {
-    fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
+impl<'tcx> MirPass<'tcx> for Inline {
+    fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
         if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
             Inliner { tcx, source }.run_pass(body);
         }
@@ -394,7 +394,6 @@ fn inline_call(&self,
 
                 let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len());
                 let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len());
-                let mut promoted_map = IndexVec::with_capacity(callee_body.promoted.len());
 
                 for mut scope in callee_body.source_scopes.iter().cloned() {
                     if scope.parent_scope.is_none() {
@@ -420,10 +419,6 @@ fn inline_call(&self,
                     local_map.push(idx);
                 }
 
-                promoted_map.extend(
-                    callee_body.promoted.iter().cloned().map(|p| caller_body.promoted.push(p))
-                );
-
                 // If the call is something like `a[*i] = f(i)`, where
                 // `i : &mut usize`, then just duplicating the `a[*i]`
                 // Place could result in two different locations if `f`
@@ -484,12 +479,12 @@ fn dest_needs_borrow(place: &Place<'_>) -> bool {
                     args: &args,
                     local_map,
                     scope_map,
-                    promoted_map,
-                    _callsite: callsite,
+                    callsite,
                     destination: dest,
                     return_block,
                     cleanup_block: cleanup,
-                    in_cleanup_block: false
+                    in_cleanup_block: false,
+                    tcx: self.tcx,
                 };
 
 
@@ -644,12 +639,12 @@ struct Integrator<'a, 'tcx> {
     args: &'a [Local],
     local_map: IndexVec<Local, Local>,
     scope_map: IndexVec<SourceScope, SourceScope>,
-    promoted_map: IndexVec<Promoted, Promoted>,
-    _callsite: CallSite<'tcx>,
+    callsite: CallSite<'tcx>,
     destination: Place<'tcx>,
     return_block: BasicBlock,
     cleanup_block: Option<BasicBlock>,
     in_cleanup_block: bool,
+    tcx: TyCtxt<'tcx>,
 }
 
 impl<'a, 'tcx> Integrator<'a, 'tcx> {
@@ -700,14 +695,14 @@ fn visit_place(&mut self,
             },
             Place {
                 base: PlaceBase::Static(box Static {
-                    kind: StaticKind::Promoted(promoted),
+                    kind: StaticKind::Promoted(_, substs),
                     ..
                 }),
                 projection: None,
             } => {
-                if let Some(p) = self.promoted_map.get(*promoted).cloned() {
-                    *promoted = p;
-                }
+                let adjusted_substs = substs.subst(self.tcx, self.callsite.substs);
+                debug!("replacing substs {:?} with {:?}", substs, adjusted_substs);
+                *substs = adjusted_substs;
             },
             _ => self.super_place(place, _ctxt, _location)
         }