From 450b6fdbaca9a266bd4330c806f2d00e4add644a Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 16 Apr 2026 09:01:37 -0700 Subject: [PATCH] Fix `EntitySet` debug formatting It was printing all keys up to the max key in the set instead of the entities actually in the set. --- cranelift/entity/src/set.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cranelift/entity/src/set.rs b/cranelift/entity/src/set.rs index e93316c15401..ed0eb43fc018 100644 --- a/cranelift/entity/src/set.rs +++ b/cranelift/entity/src/set.rs @@ -29,7 +29,7 @@ where K: fmt::Debug + EntityRef, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_set().entries(self.keys()).finish() + f.debug_set().entries(self.iter()).finish() } } @@ -199,7 +199,7 @@ where #[cfg(test)] mod tests { use super::*; - use alloc::vec::Vec; + use alloc::{format, vec::Vec}; use core::u32; // `EntityRef` impl for testing. @@ -307,4 +307,13 @@ mod tests { assert!(m.is_empty()); } + + #[test] + fn fmt_debug() { + let mut s = EntitySet::new(); + s.insert(E(2)); + s.insert(E(4)); + // The `Debug` formatting should only show the elements within the set. + assert_eq!(format!("{s:?}"), "{E(2), E(4)}"); + } }