]> git.lizzy.rs Git - rust.git/commitdiff
Mark migration code that relies on Deref unreachable
authorAman Arora <me@aman-arora.com>
Fri, 5 Feb 2021 00:55:16 +0000 (19:55 -0500)
committerAman Arora <me@aman-arora.com>
Tue, 9 Feb 2021 07:59:29 +0000 (02:59 -0500)
compiler/rustc_typeck/src/check/upvar.rs

index 4d21629cd69fcb2f2df176eb915d5cb0c0e9c42b..1ffa8c37a8032404d54f245884e1eb97c6063950 100644 (file)
@@ -698,8 +698,8 @@ fn compute_2229_migrations_precise_pass(
     ///                             freeing up memory).
     ///
     /// The way this function works is at a given call it looks at type `base_path_ty` of some base
-    /// path say P and then vector of projection slices which represent the different captures
-    /// starting off of P.
+    /// path say P and then list of projection slices which represent the different captures moved
+    /// into the closure starting off of P.
     ///
     /// This will make more sense with an example:
     ///
@@ -842,23 +842,12 @@ fn has_significant_drop_outside_of_captures(
             //   `captured_projs.first().unwrap()` safely.
             // - All entries in `captured_projs` have atleast one projection.
             //   Therefore we can call `captured_projs.first().unwrap().first().unwrap()` safely.
-            ty::Adt(def, _) if def.is_box() => {
-                // We must deref to access paths on top of a Box.
-                assert!(
-                    captured_projs
-                        .iter()
-                        .all(|projs| matches!(projs.first().unwrap().kind, ProjectionKind::Deref))
-                );
 
-                let next_ty = captured_projs.first().unwrap().first().unwrap().ty;
-                let captured_projs = captured_projs.iter().map(|projs| &projs[1..]).collect();
-                self.has_significant_drop_outside_of_captures(
-                    closure_def_id,
-                    closure_span,
-                    next_ty,
-                    captured_projs,
-                )
-            }
+            // We don't capture derefs in case of move captures, which would have be applied to
+            // access any further paths.
+            ty::Adt(def, _) if def.is_box() => unreachable!(),
+            ty::Ref(..) => unreachable!(),
+            ty::RawPtr(..) => unreachable!(),
 
             ty::Adt(def, substs) => {
                 // Multi-varaint enums are captured in entirety,
@@ -929,27 +918,7 @@ fn has_significant_drop_outside_of_captures(
                 })
             }
 
-            ty::Ref(_, deref_ty, _) => {
-                // Only Derefs can be applied to a Ref
-                assert!(
-                    captured_projs
-                        .iter()
-                        .all(|projs| matches!(projs.first().unwrap().kind, ProjectionKind::Deref))
-                );
-
-                let captured_projs = captured_projs.iter().map(|projs| &projs[1..]).collect();
-                self.has_significant_drop_outside_of_captures(
-                    closure_def_id,
-                    closure_span,
-                    deref_ty,
-                    captured_projs,
-                )
-            }
-
-            // Unsafe Ptrs are captured in their entirety, which would've have been handled in
-            // the case of single empty slice in `captured_projs`.
-            ty::RawPtr(..) => unreachable!(),
-
+            // Anything else would be completely captured and therefore handled already.
             _ => unreachable!(),
         }
     }