Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Implement `Debug` for OOM-handling `{Primary,Secondary}Map` (#12455)

Nick Fitzgerald63d8dd33dd7b
diff --git a/crates/environ/src/collections/primary_map.rs b/crates/environ/src/collections/primary_map.rs
index 5b46458f1c..6e8e044100 100644
--- a/crates/environ/src/collections/primary_map.rs
+++ b/crates/environ/src/collections/primary_map.rs
@@ -1,4 +1,7 @@
-use core::ops::{Index, IndexMut};
+use core::{
+ fmt,
+ ops::{Index, IndexMut},
+};
use cranelift_entity::EntityRef;
use wasmtime_core::error::OutOfMemory;
@@ -12,6 +15,16 @@ where
inner: cranelift_entity::PrimaryMap<K, V>,
}
+impl<K, V> fmt::Debug for PrimaryMap<K, V>
+where
+ K: EntityRef + fmt::Debug,
+ V: fmt::Debug,
+{
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Debug::fmt(&self.inner, f)
+ }
+}
+
impl<K, V> PrimaryMap<K, V>
where
K: EntityRef,
diff --git a/crates/environ/src/collections/secondary_map.rs b/crates/environ/src/collections/secondary_map.rs
index 3afb0d146f..72f2723163 100644
--- a/crates/environ/src/collections/secondary_map.rs
+++ b/crates/environ/src/collections/secondary_map.rs
@@ -1,5 +1,5 @@
use crate::error::OutOfMemory;
-use core::ops::Index;
+use core::{fmt, ops::Index};
use cranelift_entity::{EntityRef, SecondaryMap as Inner};
/// Like [`cranelift_entity::SecondaryMap`] but all allocation is fallible.
@@ -11,6 +11,16 @@ where
inner: Inner<K, V>,
}
+impl<K, V> fmt::Debug for SecondaryMap<K, V>
+where
+ K: EntityRef + fmt::Debug,
+ V: fmt::Debug + Clone,
+{
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Debug::fmt(&self.inner, f)
+ }
+}
+
impl<K, V> SecondaryMap<K, V>
where
K: EntityRef,