Skip to content

Commit 5b54640

Browse files
committed
Mark migration code that relies on Deref unreachable
1 parent 319f1ab commit 5b54640

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

compiler/rustc_typeck/src/check/upvar.rs

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
698698
/// freeing up memory).
699699
///
700700
/// The way this function works is at a given call it looks at type `base_path_ty` of some base
701-
/// path say P and then vector of projection slices which represent the different captures
702-
/// starting off of P.
701+
/// path say P and then list of projection slices which represent the different captures moved
702+
/// into the closure starting off of P.
703703
///
704704
/// This will make more sense with an example:
705705
///
@@ -842,23 +842,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
842842
// `captured_projs.first().unwrap()` safely.
843843
// - All entries in `captured_projs` have atleast one projection.
844844
// Therefore we can call `captured_projs.first().unwrap().first().unwrap()` safely.
845-
ty::Adt(def, _) if def.is_box() => {
846-
// We must deref to access paths on top of a Box.
847-
assert!(
848-
captured_projs
849-
.iter()
850-
.all(|projs| matches!(projs.first().unwrap().kind, ProjectionKind::Deref))
851-
);
852845

853-
let next_ty = captured_projs.first().unwrap().first().unwrap().ty;
854-
let captured_projs = captured_projs.iter().map(|projs| &projs[1..]).collect();
855-
self.has_significant_drop_outside_of_captures(
856-
closure_def_id,
857-
closure_span,
858-
next_ty,
859-
captured_projs,
860-
)
861-
}
846+
// We don't capture derefs in case of move captures, which would have be applied to
847+
// access any further paths.
848+
ty::Adt(def, _) if def.is_box() => unreachable!(),
849+
ty::Ref(..) => unreachable!(),
850+
ty::RawPtr(..) => unreachable!(),
862851

863852
ty::Adt(def, substs) => {
864853
// Multi-varaint enums are captured in entirety,
@@ -929,27 +918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
929918
})
930919
}
931920

932-
ty::Ref(_, deref_ty, _) => {
933-
// Only Derefs can be applied to a Ref
934-
assert!(
935-
captured_projs
936-
.iter()
937-
.all(|projs| matches!(projs.first().unwrap().kind, ProjectionKind::Deref))
938-
);
939-
940-
let captured_projs = captured_projs.iter().map(|projs| &projs[1..]).collect();
941-
self.has_significant_drop_outside_of_captures(
942-
closure_def_id,
943-
closure_span,
944-
deref_ty,
945-
captured_projs,
946-
)
947-
}
948-
949-
// Unsafe Ptrs are captured in their entirety, which would've have been handled in
950-
// the case of single empty slice in `captured_projs`.
951-
ty::RawPtr(..) => unreachable!(),
952-
921+
// Anything else would be completely captured and therefore handled already.
953922
_ => unreachable!(),
954923
}
955924
}

0 commit comments

Comments
 (0)