]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/shim.rs
Merge remote-tracking branch 'origin/master' into gen
[rust.git] / src / librustc_mir / shim.rs
index 62e762be93a71938a7a3f93ccfdc40d1186a43f7..177211e9372595343d92b4155246b05909b22b18 100644 (file)
@@ -128,6 +128,7 @@ fn temp_decl(mutability: Mutability, ty: Ty, span: Span) -> LocalDecl {
     LocalDecl {
         mutability, ty, name: None,
         source_info: SourceInfo { scope: ARGUMENT_VISIBILITY_SCOPE, span },
+        internal: false,
         is_user_variable: false
     }
 }
@@ -148,6 +149,12 @@ fn build_drop_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
 {
     debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty);
 
+    // Check if this is a generator, if so, return the drop glue for it
+    if let Some(&ty::TyS { sty: ty::TyGenerator(gen_def_id, substs, _), .. }) = ty {
+        let mir = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap();
+        return mir.subst(tcx, substs.substs);
+    }
+
     let substs = if let Some(ty) = ty {
         tcx.mk_substs(iter::once(Kind::from(ty)))
     } else {
@@ -178,6 +185,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
         ),
         IndexVec::new(),
         sig.output(),
+        None,
         local_decls_for_sig(&sig, span),
         sig.inputs().len(),
         vec![],
@@ -213,10 +221,10 @@ fn build_drop_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
 }
 
 pub struct DropShimElaborator<'a, 'tcx: 'a> {
-    mir: &'a Mir<'tcx>,
-    patch: MirPatch<'tcx>,
-    tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
-    param_env: ty::ParamEnv<'tcx>,
+    pub mir: &'a Mir<'tcx>,
+    pub patch: MirPatch<'tcx>,
+    pub tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
+    pub param_env: ty::ParamEnv<'tcx>,
 }
 
 impl<'a, 'tcx> fmt::Debug for DropShimElaborator<'a, 'tcx> {
@@ -390,6 +398,7 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
         ),
         IndexVec::new(),
         sig.output(),
+        None,
         local_decls,
         sig.inputs().len(),
         vec![],
@@ -461,6 +470,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
         ),
         IndexVec::new(),
         sig.output(),
+        None,
         local_decls,
         sig.inputs().len(),
         vec![],