From 1fb3256fcb9f616b19245eedea6503bce35e5b81 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Mon, 5 Apr 2021 13:31:11 +0200 Subject: [PATCH 1/3] Replace all `fmt.pad` with `debug_struct` --- library/core/src/any.rs | 6 +++--- library/core/src/ascii.rs | 2 +- library/core/src/ffi.rs | 2 +- library/core/src/fmt/mod.rs | 4 ++-- library/core/src/hash/mod.rs | 2 +- library/core/src/iter/sources/empty.rs | 2 +- library/core/src/slice/ascii.rs | 2 +- library/core/src/str/iter.rs | 2 +- library/std/src/collections/hash/map.rs | 4 ++-- library/std/src/collections/hash/set.rs | 2 +- library/std/src/env.rs | 6 +++--- library/std/src/io/stdio.rs | 12 ++++++------ library/std/src/io/util.rs | 6 +++--- library/std/src/process.rs | 8 ++++---- library/std/src/sync/barrier.rs | 2 +- library/std/src/sync/condvar.rs | 2 +- library/std/src/sync/mpsc/mod.rs | 2 +- library/std/src/sync/once.rs | 2 +- library/std/src/sys_common/poison.rs | 2 +- library/std/src/thread/local.rs | 8 ++++---- library/std/src/thread/mod.rs | 2 +- 21 files changed, 40 insertions(+), 40 deletions(-) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 98c34f344251e..339e874558c51 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -141,7 +141,7 @@ impl Any for T { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for dyn Any { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Any") + f.debug_struct("Any").finish() } } @@ -151,14 +151,14 @@ impl fmt::Debug for dyn Any { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for dyn Any + Send { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Any") + f.debug_struct("Any").finish() } } #[stable(feature = "any_send_sync_methods", since = "1.28.0")] impl fmt::Debug for dyn Any + Send + Sync { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Any") + f.debug_struct("Any").finish() } } diff --git a/library/core/src/ascii.rs b/library/core/src/ascii.rs index a8a25f927163c..4780d8dc7883f 100644 --- a/library/core/src/ascii.rs +++ b/library/core/src/ascii.rs @@ -145,6 +145,6 @@ impl fmt::Display for EscapeDefault { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for EscapeDefault { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("EscapeDefault { .. }") + f.debug_struct("EscapeDefault").finish_non_exhaustive() } } diff --git a/library/core/src/ffi.rs b/library/core/src/ffi.rs index 9302baa823bc5..b208ddd4b272f 100644 --- a/library/core/src/ffi.rs +++ b/library/core/src/ffi.rs @@ -53,7 +53,7 @@ pub enum c_void { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for c_void { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("c_void") + f.debug_struct("c_void").finish() } } diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 59493bb0425f3..0edb7da571725 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2220,7 +2220,7 @@ impl Debug for () { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for PhantomData { fn fmt(&self, f: &mut Formatter<'_>) -> Result { - f.pad("PhantomData") + f.debug_struct("PhantomData").finish() } } @@ -2270,7 +2270,7 @@ impl Debug for RefMut<'_, T> { #[stable(feature = "core_impl_debug", since = "1.9.0")] impl Debug for UnsafeCell { fn fmt(&self, f: &mut Formatter<'_>) -> Result { - f.pad("UnsafeCell") + f.debug_struct("UnsafeCell").finish() } } diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index 0c3303cc21094..7dbd68b73f05a 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -507,7 +507,7 @@ pub struct BuildHasherDefault(marker::PhantomData); #[stable(since = "1.9.0", feature = "core_impl_debug")] impl fmt::Debug for BuildHasherDefault { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("BuildHasherDefault") + f.debug_struct("BuildHasherDefault").finish() } } diff --git a/library/core/src/iter/sources/empty.rs b/library/core/src/iter/sources/empty.rs index 5d4a9fe8c6cc0..919c564f2872a 100644 --- a/library/core/src/iter/sources/empty.rs +++ b/library/core/src/iter/sources/empty.rs @@ -36,7 +36,7 @@ unsafe impl Sync for Empty {} #[stable(feature = "core_impl_debug", since = "1.9.0")] impl fmt::Debug for Empty { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Empty") + f.debug_struct("Empty").finish() } } diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 22fa08b979570..906dcb1e8bcee 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -146,7 +146,7 @@ impl<'a> fmt::Display for EscapeAscii<'a> { #[unstable(feature = "inherent_ascii_escape", issue = "77174")] impl<'a> fmt::Debug for EscapeAscii<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("EscapeAscii { .. }") + f.debug_struct("EscapeAscii").finish_non_exhaustive() } } diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 4eac017f9153c..7ebff180f9d73 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -1359,7 +1359,7 @@ pub struct EncodeUtf16<'a> { #[stable(feature = "collection_debug", since = "1.17.0")] impl fmt::Debug for EncodeUtf16<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("EncodeUtf16 { .. }") + f.debug_struct("EncodeUtf16").finish_non_exhaustive() } } diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 3dcc5cd2b5911..bdf559847cc85 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -2257,7 +2257,7 @@ where F: FnMut(&K, &mut V) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("DrainFilter { .. }") + f.debug_struct("DrainFilter").finish_non_exhaustive() } } @@ -2957,7 +2957,7 @@ impl Default for RandomState { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for RandomState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("RandomState { .. }") + f.debug_struct("RandomState").finish_non_exhaustive() } } diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 8c801b9f1285d..5220c8ad70977 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -1533,7 +1533,7 @@ where F: FnMut(&K) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("DrainFilter { .. }") + f.debug_struct("DrainFilter").finish_non_exhaustive() } } diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 9763a2da34151..8f8d4e3a89832 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -154,7 +154,7 @@ impl Iterator for Vars { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Vars { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Vars { .. }") + f.debug_struct("Vars").finish_non_exhaustive() } } @@ -172,7 +172,7 @@ impl Iterator for VarsOs { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for VarsOs { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("VarsOs { .. }") + f.debug_struct("VarOs").finish_non_exhaustive() } } @@ -419,7 +419,7 @@ impl<'a> Iterator for SplitPaths<'a> { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for SplitPaths<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("SplitPaths { .. }") + f.debug_struct("SplitPaths").finish_non_exhaustive() } } diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 1e72c9e0611ea..c2e0b24ba8327 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -373,7 +373,7 @@ impl Stdin { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stdin { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Stdin { .. }") + f.debug_struct("Stdin").finish_non_exhaustive() } } @@ -467,7 +467,7 @@ impl BufRead for StdinLock<'_> { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for StdinLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("StdinLock { .. }") + f.debug_struct("StdinLock").finish_non_exhaustive() } } @@ -607,7 +607,7 @@ impl Stdout { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stdout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Stdout { .. }") + f.debug_struct("Stdout").finish_non_exhaustive() } } @@ -689,7 +689,7 @@ impl Write for StdoutLock<'_> { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for StdoutLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("StdoutLock { .. }") + f.debug_struct("StdoutLock").finish_non_exhaustive() } } @@ -804,7 +804,7 @@ impl Stderr { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stderr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Stderr { .. }") + f.debug_struct("Stderr").finish_non_exhaustive() } } @@ -886,7 +886,7 @@ impl Write for StderrLock<'_> { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for StderrLock<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("StderrLock { .. }") + f.debug_struct("StderrLock").finish_non_exhaustive() } } diff --git a/library/std/src/io/util.rs b/library/std/src/io/util.rs index f472361f916db..73f2f3eb3f5dc 100644 --- a/library/std/src/io/util.rs +++ b/library/std/src/io/util.rs @@ -78,7 +78,7 @@ impl Seek for Empty { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Empty { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Empty { .. }") + f.debug_struct("Empty").finish_non_exhaustive() } } @@ -150,7 +150,7 @@ impl Read for Repeat { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Repeat { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Repeat { .. }") + f.debug_struct("Repeat").finish_non_exhaustive() } } @@ -236,6 +236,6 @@ impl Write for &Sink { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Sink { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Sink { .. }") + f.debug_struct("Sink").finish_non_exhaustive() } } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 5690de681cab9..931b3b600a302 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -312,7 +312,7 @@ impl FromInner for ChildStdin { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for ChildStdin { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("ChildStdin { .. }") + f.debug_struct("ChildStdin").finish_non_exhaustive() } } @@ -373,7 +373,7 @@ impl FromInner for ChildStdout { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for ChildStdout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("ChildStdout { .. }") + f.debug_struct("ChildStdout").finish_non_exhaustive() } } @@ -434,7 +434,7 @@ impl FromInner for ChildStderr { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for ChildStderr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("ChildStderr { .. }") + f.debug_struct("ChildStderr").finish_non_exhaustive() } } @@ -1257,7 +1257,7 @@ impl FromInner for Stdio { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Stdio { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Stdio { .. }") + f.debug_struct("Stdio").finish_non_exhaustive() } } diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index eab26b6c7150c..a17b82f82e8c2 100644 --- a/library/std/src/sync/barrier.rs +++ b/library/std/src/sync/barrier.rs @@ -60,7 +60,7 @@ pub struct BarrierWaitResult(bool); #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Barrier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Barrier { .. }") + f.debug_struct("Barrier").finish_non_exhaustive() } } diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index ffc1e57f4e03f..60be63c9543fa 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -548,7 +548,7 @@ impl Condvar { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Condvar { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Condvar { .. }") + f.debug_struct("Condvar").finish_non_exhaustive() } } diff --git a/library/std/src/sync/mpsc/mod.rs b/library/std/src/sync/mpsc/mod.rs index c8f0a6b99fe6b..ea1d598d26461 100644 --- a/library/std/src/sync/mpsc/mod.rs +++ b/library/std/src/sync/mpsc/mod.rs @@ -1477,7 +1477,7 @@ impl fmt::Debug for Receiver { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for SendError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "SendError(..)".fmt(f) + f.debug_struct("SendError").finish_non_exhaustive() } } diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index a24a5cb2ae39f..6da6c18e47799 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -481,7 +481,7 @@ fn wait(state_and_queue: &AtomicUsize, mut current_state: usize) { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Once { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Once { .. }") + f.debug_struct("Once").finish_non_exhaustive() } } diff --git a/library/std/src/sys_common/poison.rs b/library/std/src/sys_common/poison.rs index 2ab2c700a1bf1..1f71187f1b466 100644 --- a/library/std/src/sys_common/poison.rs +++ b/library/std/src/sys_common/poison.rs @@ -127,7 +127,7 @@ pub type TryLockResult = Result>; #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for PoisonError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "PoisonError { inner: .. }".fmt(f) + f.debug_struct("PoisonError").finish_non_exhaustive() } } diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index 37525e50604dd..f0355aa1e1606 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -100,7 +100,7 @@ pub struct LocalKey { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for LocalKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("LocalKey { .. }") + f.debug_struct("LocalKey").finish_non_exhaustive() } } @@ -472,7 +472,7 @@ pub mod statik { impl fmt::Debug for Key { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Key { .. }") + f.debug_struct("Key").finish_non_exhaustive() } } @@ -537,7 +537,7 @@ pub mod fast { impl fmt::Debug for Key { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Key { .. }") + f.debug_struct("Key").finish_non_exhaustive() } } @@ -651,7 +651,7 @@ pub mod os { impl fmt::Debug for Key { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("Key { .. }") + f.debug_struct("Key").finish_non_exhaustive() } } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 54e39f762741f..30d8c2a1b6fa0 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1413,7 +1413,7 @@ impl IntoInner for JoinHandle { #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for JoinHandle { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("JoinHandle { .. }") + f.debug_struct("JoinHandle").finish_non_exhaustive() } } From fdae75738b8d9b1df6cf1f24de9a40ac12046dd8 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Wed, 21 Apr 2021 14:51:04 +0200 Subject: [PATCH 2/3] Change the `Debug` impl of `Any` and `UnsafeCell` to use `finish_non_exhaustive` --- library/core/src/any.rs | 6 +++--- library/core/src/fmt/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 339e874558c51..5e1725cfc7a63 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -141,7 +141,7 @@ impl Any for T { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for dyn Any { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Any").finish() + f.debug_struct("Any").finish_non_exhaustive() } } @@ -151,14 +151,14 @@ impl fmt::Debug for dyn Any { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for dyn Any + Send { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Any").finish() + f.debug_struct("Any").finish_non_exhaustive() } } #[stable(feature = "any_send_sync_methods", since = "1.28.0")] impl fmt::Debug for dyn Any + Send + Sync { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Any").finish() + f.debug_struct("Any").finish_non_exhaustive() } } diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 0edb7da571725..87042d95fbef0 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2270,7 +2270,7 @@ impl Debug for RefMut<'_, T> { #[stable(feature = "core_impl_debug", since = "1.9.0")] impl Debug for UnsafeCell { fn fmt(&self, f: &mut Formatter<'_>) -> Result { - f.debug_struct("UnsafeCell").finish() + f.debug_struct("UnsafeCell").finish_non_exhaustive() } } From fccc75cf8299158125f5785855d7235a178434d7 Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Wed, 21 Apr 2021 15:45:41 +0200 Subject: [PATCH 3/3] Fix `alloc::test::test_show` --- library/alloc/src/tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/tests.rs b/library/alloc/src/tests.rs index bddaab0c76188..b4741c35c583f 100644 --- a/library/alloc/src/tests.rs +++ b/library/alloc/src/tests.rs @@ -49,17 +49,17 @@ fn test_show() { let b = Box::new(Test) as Box; let a_str = format!("{:?}", a); let b_str = format!("{:?}", b); - assert_eq!(a_str, "Any"); - assert_eq!(b_str, "Any"); + assert_eq!(a_str, "Any { .. }"); + assert_eq!(b_str, "Any { .. }"); static EIGHT: usize = 8; static TEST: Test = Test; let a = &EIGHT as &dyn Any; let b = &TEST as &dyn Any; let s = format!("{:?}", a); - assert_eq!(s, "Any"); + assert_eq!(s, "Any { .. }"); let s = format!("{:?}", b); - assert_eq!(s, "Any"); + assert_eq!(s, "Any { .. }"); } #[test]