From 624c5da1aacf44354dead47dce5033f1806e9228 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 26 Jul 2019 02:58:37 -0400 Subject: [PATCH 1/2] impl Debug for Chars --- src/liballoc/tests/str.rs | 10 ++++++++++ src/libcore/str/mod.rs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index b197516403f78..20132fea65118 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -1108,6 +1108,16 @@ fn test_iterator_last() { assert_eq!(it.last(), Some('m')); } +#[test] +fn test_chars_display() { + let s = "ศไทย中华Việt Nam"; + let c = s.chars(); + assert_eq!( + format!("{:?}", c), + r#"Chars(['ศ', 'ไ', 'ท', 'ย', '中', '华', 'V', 'i', 'ệ', 't', ' ', 'N', 'a', 'm'])"# + ); +} + #[test] fn test_bytesator() { let s = "ศไทย中华Việt Nam"; diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4ecaa37460c66..ee791748c1ddf 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -464,7 +464,7 @@ Section: Iterators /// /// [`chars`]: ../../std/primitive.str.html#method.chars /// [`str`]: ../../std/primitive.str.html -#[derive(Clone, Debug)] +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chars<'a> { iter: slice::Iter<'a, u8> @@ -600,6 +600,16 @@ impl<'a> Iterator for Chars<'a> { } } +#[stable(feature = "chars_debug_impl", since = "1.38.0")] +impl<'a> fmt::Debug for Chars<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Chars(")?; + f.debug_list().entries(self.clone()).finish()?; + write!(f, ")")?; + Ok(()) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a> DoubleEndedIterator for Chars<'a> { #[inline] From 3325ff6df47f75cdf4891b35dcaf565f7ffb22cf Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 29 Jul 2019 12:26:59 -0400 Subject: [PATCH 2/2] comments from @lzutao --- src/liballoc/tests/str.rs | 2 +- src/libcore/str/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index 20132fea65118..c5198ca39fedf 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -1109,7 +1109,7 @@ fn test_iterator_last() { } #[test] -fn test_chars_display() { +fn test_chars_debug() { let s = "ศไทย中华Việt Nam"; let c = s.chars(); assert_eq!( diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index ee791748c1ddf..4faf9ff4d2ee2 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -601,7 +601,7 @@ impl<'a> Iterator for Chars<'a> { } #[stable(feature = "chars_debug_impl", since = "1.38.0")] -impl<'a> fmt::Debug for Chars<'a> { +impl fmt::Debug for Chars<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Chars(")?; f.debug_list().entries(self.clone()).finish()?;