Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion library/std/src/sys_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//! Progress on this is tracked in #84187.

#![allow(missing_docs)]
#![allow(missing_debug_implementations)]

#[cfg(test)]
mod tests;
Expand Down
17 changes: 17 additions & 0 deletions library/std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,23 @@ impl Iterator for EncodeWide<'_> {
#[stable(feature = "encode_wide_fused_iterator", since = "1.62.0")]
impl FusedIterator for EncodeWide<'_> {}

#[stable(feature = "encode_wide_debug", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for EncodeWide<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct CodeUnit(u16);
impl fmt::Debug for CodeUnit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#06X}", self.0)
}
}

write!(f, "EncodeWide(")?;
f.debug_list().entries(self.clone().map(CodeUnit)).finish()?;
write!(f, ")")?;
Ok(())
}
}

impl Hash for CodePoint {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sys_common/wtf8/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,17 @@ fn wtf8_encode_wide_size_hint() {
assert!(iter.next().is_none());
}

#[test]
fn wtf8_encode_wide_debug() {
let mut string = Wtf8Buf::from_str("aé ");
string.push(CodePoint::from_u32(0xD83D).unwrap());
string.push_char('💩');
assert_eq!(
format!("{:?}", string.encode_wide()),
r#"EncodeWide([0x0061, 0x00E9, 0x0020, 0xD83D, 0xD83D, 0xDCA9])"#
);
}

#[test]
fn wtf8_clone_into() {
let mut string = Wtf8Buf::new();
Expand Down
Loading