Skip to content

Commit da70164

Browse files
committed
move drop bomb from OpaqueTypeStorage into InferCtxt's Drop
1 parent ab63680 commit da70164

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ pub struct InferCtxt<'tcx> {
321321

322322
impl<'tcx> Drop for InferCtxt<'tcx> {
323323
fn drop(&mut self) {
324-
// Defuse the drop bomb in the OpaqueTypeStorage when we're in TypingMode::Borrowck,
325-
// and the InferCtxt doesn't consider regions. This is okay since in `Borrowck`,
326-
// the only reason we care about opaques is in relation to regions.
324+
let mut inner = self.inner.borrow_mut();
325+
let opaque_type_storage = &mut inner.opaque_type_storage;
326+
327+
// No need for the drop bomb when we're in TypingMode::Borrowck, and the InferCtxt doesn't consider regions.
328+
// This is okay since in `Borrowck`, the only reason we care about opaques is in relation to regions.
327329
// In some places *after* typeck, like in lints we use `TypingMode::Borrowck`
328330
// to prevent defining opaque types and we simply don't care about regions.
329331
match self.typing_mode() {
@@ -333,10 +335,14 @@ impl<'tcx> Drop for InferCtxt<'tcx> {
333335
| TypingMode::PostAnalysis => {}
334336
TypingMode::Borrowck { .. } => {
335337
if !self.considering_regions {
336-
let _ = self.inner.borrow_mut().opaque_type_storage.take_opaque_types();
338+
return;
337339
}
338340
}
339341
}
342+
343+
if !opaque_type_storage.is_empty() {
344+
ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{opaque_type_storage:?}")));
345+
}
340346
}
341347
}
342348

compiler/rustc_infer/src/infer/opaque_types/table.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::Deref;
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::undo_log::UndoLogs;
55
use rustc_middle::bug;
6-
use rustc_middle::ty::{self, OpaqueTypeKey, ProvisionalHiddenType, Ty};
6+
use rustc_middle::ty::{OpaqueTypeKey, ProvisionalHiddenType, Ty};
77
use tracing::instrument;
88

99
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
@@ -121,14 +121,6 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
121121
}
122122
}
123123

124-
impl<'tcx> Drop for OpaqueTypeStorage<'tcx> {
125-
fn drop(&mut self) {
126-
if !self.is_empty() {
127-
ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{:?}", self.opaque_types)));
128-
}
129-
}
130-
}
131-
132124
pub struct OpaqueTypeTable<'a, 'tcx> {
133125
storage: &'a mut OpaqueTypeStorage<'tcx>,
134126

0 commit comments

Comments
 (0)