Skip to content

Commit 4e7f1fa

Browse files
committed
post-drop-elab check-const: explain why we still check qualifs
1 parent 41b315a commit 4e7f1fa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/rustc_mir/src/transform/check_consts/post_drop_elaboration.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,20 @@ impl Visitor<'tcx> for CheckLiveDrops<'mir, 'tcx> {
7979
mir::TerminatorKind::Drop { place: dropped_place, .. } => {
8080
let dropped_ty = dropped_place.ty(self.body, self.tcx).ty;
8181
if !NeedsDrop::in_any_value_of_ty(self.ccx, dropped_ty) {
82-
return;
82+
bug!(
83+
"Drop elaboration left behind a Drop for a type that does not need dropping"
84+
);
8385
}
8486

8587
if dropped_place.is_indirect() {
8688
self.check_live_drop(terminator.source_info.span);
8789
return;
8890
}
8991

92+
// Drop elaboration is not precise enough to accept code like
93+
// `src/test/ui/consts/control-flow/drop-pass.rs`; e.g., when an `Option<Vec<T>>` is
94+
// initialized with `None` and never changed, it still emits drop glue.
95+
// Hence we additionally check the qualifs here to allow more code to pass.
9096
if self.qualifs.needs_drop(self.ccx, dropped_place.local, location) {
9197
// Use the span where the dropped local was declared for the error.
9298
let span = self.body.local_decls[dropped_place.local].source_info.span;

0 commit comments

Comments
 (0)