]> git.lizzy.rs Git - rust.git/commitdiff
Add some suggested comments around drops
authorAlex Crichton <alex@alexcrichton.com>
Fri, 25 Aug 2017 14:38:57 +0000 (07:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 25 Aug 2017 14:38:57 +0000 (07:38 -0700)
src/librustc_mir/transform/generator.rs
src/librustc_mir/util/elaborate_drops.rs

index d47e722de84479aa773cbcf6735eebe887ceabdc..f774b748112a5ec8f7d5a6bd2715fab5eac60c56 100644 (file)
@@ -331,12 +331,16 @@ fn insert_entry_point<'tcx>(mir: &mut Mir<'tcx>,
 }
 
 fn elaborate_generator_drops<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                                      def_id: DefId,
-                                      mir: &mut Mir<'tcx>) {
+                                       def_id: DefId,
+                                       mir: &mut Mir<'tcx>) {
     use util::elaborate_drops::{elaborate_drop, Unwind};
     use util::patch::MirPatch;
     use shim::DropShimElaborator;
 
+    // Note that `elaborate_drops` only drops the upvars of a generator, and
+    // this is ok because `open_drop` can only be reached within that own
+    // generator's resume function.
+
     let param_env = tcx.param_env(def_id);
     let gen = self_arg();
 
index 0abc5c8743171d587afb7a7dd019edb6b55030c5..e1a52ab9723cfd76a7fa6013e342de27cbd3925b 100644 (file)
@@ -752,6 +752,9 @@ fn drop_loop_pair(&mut self, ety: Ty<'tcx>, ptr_based: bool) -> BasicBlock {
     fn open_drop<'a>(&mut self) -> BasicBlock {
         let ty = self.lvalue_ty(self.lvalue);
         match ty.sty {
+            // Note that `elaborate_drops` only drops the upvars of a generator,
+            // and this is ok because `open_drop` here can only be reached
+            // within that own generator's resume function.
             ty::TyClosure(def_id, substs) |
             ty::TyGenerator(def_id, substs, _) => {
                 let tys : Vec<_> = substs.upvar_tys(def_id, self.tcx()).collect();