about summary refs log tree commit diff
path: root/compiler/rustc_infer
diff options
context:
space:
mode:
authorOli Scherer <github35764891676564198441@oli-obk.de>2021-08-20 13:33:06 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-02-02 15:40:10 +0000
commita4c1cec4f8d27fcff7a3fca2276bec5e767696e9 (patch)
treed0ca6b6905789da85674abd4d1fd878ef1fbc6ed /compiler/rustc_infer
parentd49b0746f6c0cf41e94e4bbd1592c52082a9cad7 (diff)
downloadrust-a4c1cec4f8d27fcff7a3fca2276bec5e767696e9.tar.gz
rust-a4c1cec4f8d27fcff7a3fca2276bec5e767696e9.zip
Add some sanity assertions to make sure we use the opaque types correctly
Diffstat (limited to 'compiler/rustc_infer')
-rw-r--r--compiler/rustc_infer/src/infer/opaque_types/table.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs
index 11eeeb08c98..6b5d55784b2 100644
--- a/compiler/rustc_infer/src/infer/opaque_types/table.rs
+++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs
@@ -6,7 +6,7 @@ use crate::infer::InferCtxtUndoLogs;
 
 use super::{OpaqueTypeDecl, OpaqueTypeMap};
 
-#[derive(Default)]
+#[derive(Default, Debug)]
 pub struct OpaqueTypeStorage<'tcx> {
     // Opaque types found in explicit return types and their
     // associated fresh inference variable. Writeback resolves these
@@ -23,6 +23,7 @@ pub struct OpaqueTypeStorage<'tcx> {
 }
 
 impl<'tcx> OpaqueTypeStorage<'tcx> {
+    #[instrument(level = "debug")]
     pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>) {
         match self.opaque_types.remove(&key) {
             None => bug!("reverted opaque type inference that was never registered"),
@@ -42,6 +43,7 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
         self.opaque_types.clone()
     }
 
+    #[instrument(level = "debug")]
     pub fn take_opaque_types(&mut self) -> OpaqueTypeMap<'tcx> {
         std::mem::take(&mut self.opaque_types)
     }
@@ -54,6 +56,13 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
         OpaqueTypeTable { storage: self, undo_log }
     }
 }
+
+impl<'tcx> Drop for OpaqueTypeStorage<'tcx> {
+    fn drop(&mut self) {
+        assert!(self.opaque_types.is_empty(), "{:?}", self.opaque_types);
+    }
+}
+
 pub struct OpaqueTypeTable<'a, 'tcx> {
     storage: &'a mut OpaqueTypeStorage<'tcx>,
 
@@ -61,6 +70,7 @@ pub struct OpaqueTypeTable<'a, 'tcx> {
 }
 
 impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
+    #[instrument(skip(self), level = "debug")]
     pub fn register(&mut self, key: OpaqueTypeKey<'tcx>, decl: OpaqueTypeDecl<'tcx>) {
         self.undo_log.push(key);
         self.storage.opaque_types.insert(key, decl);