Skip to content

Commit 23a410e

Browse files
authored
Fix EntitySet debug formatting (#13185)
It was printing all keys up to the max key in the set instead of the entities actually in the set.
1 parent dfbe997 commit 23a410e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

cranelift/entity/src/set.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
K: fmt::Debug + EntityRef,
3030
{
3131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32-
f.debug_set().entries(self.keys()).finish()
32+
f.debug_set().entries(self.iter()).finish()
3333
}
3434
}
3535

@@ -199,7 +199,7 @@ where
199199
#[cfg(test)]
200200
mod tests {
201201
use super::*;
202-
use alloc::vec::Vec;
202+
use alloc::{format, vec::Vec};
203203
use core::u32;
204204

205205
// `EntityRef` impl for testing.
@@ -307,4 +307,13 @@ mod tests {
307307

308308
assert!(m.is_empty());
309309
}
310+
311+
#[test]
312+
fn fmt_debug() {
313+
let mut s = EntitySet::new();
314+
s.insert(E(2));
315+
s.insert(E(4));
316+
// The `Debug` formatting should only show the elements within the set.
317+
assert_eq!(format!("{s:?}"), "{E(2), E(4)}");
318+
}
310319
}

0 commit comments

Comments
 (0)