Skip to content

Commit a7a7737

Browse files
authoredApr 21, 2021
Rollup merge of #84013 - CDirkx:fmt, r=m-ou-se
Replace all `fmt.pad` with `debug_struct` This replaces any occurrence of: - `f.pad("X")` with `f.debug_struct("X").finish()` - `f.pad("X { .. }")` with `f.debug_struct("X").finish_non_exhaustive()` This is in line with existing formatting code such as https://github.com/rust-lang/rust/blob/125505306744a0a5bb01d62337260a95d9ff8d57/library/std/src/sync/mpsc/mod.rs#L1470-L1475
2 parents b849326 + fccc75c commit a7a7737

File tree

22 files changed

+44
-44
lines changed

22 files changed

+44
-44
lines changed
 

‎library/alloc/src/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ fn test_show() {
4949
let b = Box::new(Test) as Box<dyn Any>;
5050
let a_str = format!("{:?}", a);
5151
let b_str = format!("{:?}", b);
52-
assert_eq!(a_str, "Any");
53-
assert_eq!(b_str, "Any");
52+
assert_eq!(a_str, "Any { .. }");
53+
assert_eq!(b_str, "Any { .. }");
5454

5555
static EIGHT: usize = 8;
5656
static TEST: Test = Test;
5757
let a = &EIGHT as &dyn Any;
5858
let b = &TEST as &dyn Any;
5959
let s = format!("{:?}", a);
60-
assert_eq!(s, "Any");
60+
assert_eq!(s, "Any { .. }");
6161
let s = format!("{:?}", b);
62-
assert_eq!(s, "Any");
62+
assert_eq!(s, "Any { .. }");
6363
}
6464

6565
#[test]

‎library/core/src/any.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<T: 'static + ?Sized> Any for T {
141141
#[stable(feature = "rust1", since = "1.0.0")]
142142
impl fmt::Debug for dyn Any {
143143
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144-
f.pad("Any")
144+
f.debug_struct("Any").finish_non_exhaustive()
145145
}
146146
}
147147

@@ -151,14 +151,14 @@ impl fmt::Debug for dyn Any {
151151
#[stable(feature = "rust1", since = "1.0.0")]
152152
impl fmt::Debug for dyn Any + Send {
153153
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154-
f.pad("Any")
154+
f.debug_struct("Any").finish_non_exhaustive()
155155
}
156156
}
157157

158158
#[stable(feature = "any_send_sync_methods", since = "1.28.0")]
159159
impl fmt::Debug for dyn Any + Send + Sync {
160160
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
161-
f.pad("Any")
161+
f.debug_struct("Any").finish_non_exhaustive()
162162
}
163163
}
164164

‎library/core/src/ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ impl fmt::Display for EscapeDefault {
145145
#[stable(feature = "std_debug", since = "1.16.0")]
146146
impl fmt::Debug for EscapeDefault {
147147
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148-
f.pad("EscapeDefault { .. }")
148+
f.debug_struct("EscapeDefault").finish_non_exhaustive()
149149
}
150150
}

‎library/core/src/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub enum c_void {
5353
#[stable(feature = "std_debug", since = "1.16.0")]
5454
impl fmt::Debug for c_void {
5555
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56-
f.pad("c_void")
56+
f.debug_struct("c_void").finish()
5757
}
5858
}
5959

‎library/core/src/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ impl Debug for () {
22202220
#[stable(feature = "rust1", since = "1.0.0")]
22212221
impl<T: ?Sized> Debug for PhantomData<T> {
22222222
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2223-
f.pad("PhantomData")
2223+
f.debug_struct("PhantomData").finish()
22242224
}
22252225
}
22262226

@@ -2270,7 +2270,7 @@ impl<T: ?Sized + Debug> Debug for RefMut<'_, T> {
22702270
#[stable(feature = "core_impl_debug", since = "1.9.0")]
22712271
impl<T: ?Sized> Debug for UnsafeCell<T> {
22722272
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2273-
f.pad("UnsafeCell")
2273+
f.debug_struct("UnsafeCell").finish_non_exhaustive()
22742274
}
22752275
}
22762276

‎library/core/src/hash/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub struct BuildHasherDefault<H>(marker::PhantomData<H>);
507507
#[stable(since = "1.9.0", feature = "core_impl_debug")]
508508
impl<H> fmt::Debug for BuildHasherDefault<H> {
509509
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
510-
f.pad("BuildHasherDefault")
510+
f.debug_struct("BuildHasherDefault").finish()
511511
}
512512
}
513513

‎library/core/src/iter/sources/empty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ unsafe impl<T> Sync for Empty<T> {}
3636
#[stable(feature = "core_impl_debug", since = "1.9.0")]
3737
impl<T> fmt::Debug for Empty<T> {
3838
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39-
f.pad("Empty")
39+
f.debug_struct("Empty").finish()
4040
}
4141
}
4242

‎library/core/src/slice/ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> fmt::Display for EscapeAscii<'a> {
146146
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
147147
impl<'a> fmt::Debug for EscapeAscii<'a> {
148148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149-
f.pad("EscapeAscii { .. }")
149+
f.debug_struct("EscapeAscii").finish_non_exhaustive()
150150
}
151151
}
152152

‎library/core/src/str/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ pub struct EncodeUtf16<'a> {
13591359
#[stable(feature = "collection_debug", since = "1.17.0")]
13601360
impl fmt::Debug for EncodeUtf16<'_> {
13611361
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1362-
f.pad("EncodeUtf16 { .. }")
1362+
f.debug_struct("EncodeUtf16").finish_non_exhaustive()
13631363
}
13641364
}
13651365

‎library/std/src/collections/hash/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ where
22572257
F: FnMut(&K, &mut V) -> bool,
22582258
{
22592259
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2260-
f.pad("DrainFilter { .. }")
2260+
f.debug_struct("DrainFilter").finish_non_exhaustive()
22612261
}
22622262
}
22632263

@@ -2957,7 +2957,7 @@ impl Default for RandomState {
29572957
#[stable(feature = "std_debug", since = "1.16.0")]
29582958
impl fmt::Debug for RandomState {
29592959
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2960-
f.pad("RandomState { .. }")
2960+
f.debug_struct("RandomState").finish_non_exhaustive()
29612961
}
29622962
}
29632963

‎library/std/src/collections/hash/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ where
15331533
F: FnMut(&K) -> bool,
15341534
{
15351535
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1536-
f.pad("DrainFilter { .. }")
1536+
f.debug_struct("DrainFilter").finish_non_exhaustive()
15371537
}
15381538
}
15391539

‎library/std/src/env.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Iterator for Vars {
154154
#[stable(feature = "std_debug", since = "1.16.0")]
155155
impl fmt::Debug for Vars {
156156
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157-
f.pad("Vars { .. }")
157+
f.debug_struct("Vars").finish_non_exhaustive()
158158
}
159159
}
160160

@@ -172,7 +172,7 @@ impl Iterator for VarsOs {
172172
#[stable(feature = "std_debug", since = "1.16.0")]
173173
impl fmt::Debug for VarsOs {
174174
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175-
f.pad("VarsOs { .. }")
175+
f.debug_struct("VarOs").finish_non_exhaustive()
176176
}
177177
}
178178

@@ -419,7 +419,7 @@ impl<'a> Iterator for SplitPaths<'a> {
419419
#[stable(feature = "std_debug", since = "1.16.0")]
420420
impl fmt::Debug for SplitPaths<'_> {
421421
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
422-
f.pad("SplitPaths { .. }")
422+
f.debug_struct("SplitPaths").finish_non_exhaustive()
423423
}
424424
}
425425

‎library/std/src/io/stdio.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl Stdin {
373373
#[stable(feature = "std_debug", since = "1.16.0")]
374374
impl fmt::Debug for Stdin {
375375
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
376-
f.pad("Stdin { .. }")
376+
f.debug_struct("Stdin").finish_non_exhaustive()
377377
}
378378
}
379379

@@ -467,7 +467,7 @@ impl BufRead for StdinLock<'_> {
467467
#[stable(feature = "std_debug", since = "1.16.0")]
468468
impl fmt::Debug for StdinLock<'_> {
469469
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
470-
f.pad("StdinLock { .. }")
470+
f.debug_struct("StdinLock").finish_non_exhaustive()
471471
}
472472
}
473473

@@ -607,7 +607,7 @@ impl Stdout {
607607
#[stable(feature = "std_debug", since = "1.16.0")]
608608
impl fmt::Debug for Stdout {
609609
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
610-
f.pad("Stdout { .. }")
610+
f.debug_struct("Stdout").finish_non_exhaustive()
611611
}
612612
}
613613

@@ -689,7 +689,7 @@ impl Write for StdoutLock<'_> {
689689
#[stable(feature = "std_debug", since = "1.16.0")]
690690
impl fmt::Debug for StdoutLock<'_> {
691691
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
692-
f.pad("StdoutLock { .. }")
692+
f.debug_struct("StdoutLock").finish_non_exhaustive()
693693
}
694694
}
695695

@@ -804,7 +804,7 @@ impl Stderr {
804804
#[stable(feature = "std_debug", since = "1.16.0")]
805805
impl fmt::Debug for Stderr {
806806
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
807-
f.pad("Stderr { .. }")
807+
f.debug_struct("Stderr").finish_non_exhaustive()
808808
}
809809
}
810810

@@ -886,7 +886,7 @@ impl Write for StderrLock<'_> {
886886
#[stable(feature = "std_debug", since = "1.16.0")]
887887
impl fmt::Debug for StderrLock<'_> {
888888
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
889-
f.pad("StderrLock { .. }")
889+
f.debug_struct("StderrLock").finish_non_exhaustive()
890890
}
891891
}
892892

‎library/std/src/io/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Seek for Empty {
7878
#[stable(feature = "std_debug", since = "1.16.0")]
7979
impl fmt::Debug for Empty {
8080
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81-
f.pad("Empty { .. }")
81+
f.debug_struct("Empty").finish_non_exhaustive()
8282
}
8383
}
8484

@@ -150,7 +150,7 @@ impl Read for Repeat {
150150
#[stable(feature = "std_debug", since = "1.16.0")]
151151
impl fmt::Debug for Repeat {
152152
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153-
f.pad("Repeat { .. }")
153+
f.debug_struct("Repeat").finish_non_exhaustive()
154154
}
155155
}
156156

@@ -236,6 +236,6 @@ impl Write for &Sink {
236236
#[stable(feature = "std_debug", since = "1.16.0")]
237237
impl fmt::Debug for Sink {
238238
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
239-
f.pad("Sink { .. }")
239+
f.debug_struct("Sink").finish_non_exhaustive()
240240
}
241241
}

‎library/std/src/process.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl FromInner<AnonPipe> for ChildStdin {
312312
#[stable(feature = "std_debug", since = "1.16.0")]
313313
impl fmt::Debug for ChildStdin {
314314
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
315-
f.pad("ChildStdin { .. }")
315+
f.debug_struct("ChildStdin").finish_non_exhaustive()
316316
}
317317
}
318318

@@ -373,7 +373,7 @@ impl FromInner<AnonPipe> for ChildStdout {
373373
#[stable(feature = "std_debug", since = "1.16.0")]
374374
impl fmt::Debug for ChildStdout {
375375
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
376-
f.pad("ChildStdout { .. }")
376+
f.debug_struct("ChildStdout").finish_non_exhaustive()
377377
}
378378
}
379379

@@ -434,7 +434,7 @@ impl FromInner<AnonPipe> for ChildStderr {
434434
#[stable(feature = "std_debug", since = "1.16.0")]
435435
impl fmt::Debug for ChildStderr {
436436
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
437-
f.pad("ChildStderr { .. }")
437+
f.debug_struct("ChildStderr").finish_non_exhaustive()
438438
}
439439
}
440440

@@ -1257,7 +1257,7 @@ impl FromInner<imp::Stdio> for Stdio {
12571257
#[stable(feature = "std_debug", since = "1.16.0")]
12581258
impl fmt::Debug for Stdio {
12591259
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1260-
f.pad("Stdio { .. }")
1260+
f.debug_struct("Stdio").finish_non_exhaustive()
12611261
}
12621262
}
12631263

‎library/std/src/sync/barrier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct BarrierWaitResult(bool);
6060
#[stable(feature = "std_debug", since = "1.16.0")]
6161
impl fmt::Debug for Barrier {
6262
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63-
f.pad("Barrier { .. }")
63+
f.debug_struct("Barrier").finish_non_exhaustive()
6464
}
6565
}
6666

‎library/std/src/sync/condvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl Condvar {
548548
#[stable(feature = "std_debug", since = "1.16.0")]
549549
impl fmt::Debug for Condvar {
550550
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
551-
f.pad("Condvar { .. }")
551+
f.debug_struct("Condvar").finish_non_exhaustive()
552552
}
553553
}
554554

‎library/std/src/sync/mpsc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ impl<T> fmt::Debug for Receiver<T> {
14771477
#[stable(feature = "rust1", since = "1.0.0")]
14781478
impl<T> fmt::Debug for SendError<T> {
14791479
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1480-
"SendError(..)".fmt(f)
1480+
f.debug_struct("SendError").finish_non_exhaustive()
14811481
}
14821482
}
14831483

‎library/std/src/sync/once.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ fn wait(state_and_queue: &AtomicUsize, mut current_state: usize) {
481481
#[stable(feature = "std_debug", since = "1.16.0")]
482482
impl fmt::Debug for Once {
483483
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
484-
f.pad("Once { .. }")
484+
f.debug_struct("Once").finish_non_exhaustive()
485485
}
486486
}
487487

‎library/std/src/sys_common/poison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;
127127
#[stable(feature = "rust1", since = "1.0.0")]
128128
impl<T> fmt::Debug for PoisonError<T> {
129129
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130-
"PoisonError { inner: .. }".fmt(f)
130+
f.debug_struct("PoisonError").finish_non_exhaustive()
131131
}
132132
}
133133

‎library/std/src/thread/local.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct LocalKey<T: 'static> {
100100
#[stable(feature = "std_debug", since = "1.16.0")]
101101
impl<T: 'static> fmt::Debug for LocalKey<T> {
102102
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103-
f.pad("LocalKey { .. }")
103+
f.debug_struct("LocalKey").finish_non_exhaustive()
104104
}
105105
}
106106

@@ -472,7 +472,7 @@ pub mod statik {
472472

473473
impl<T> fmt::Debug for Key<T> {
474474
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
475-
f.pad("Key { .. }")
475+
f.debug_struct("Key").finish_non_exhaustive()
476476
}
477477
}
478478

@@ -537,7 +537,7 @@ pub mod fast {
537537

538538
impl<T> fmt::Debug for Key<T> {
539539
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
540-
f.pad("Key { .. }")
540+
f.debug_struct("Key").finish_non_exhaustive()
541541
}
542542
}
543543

@@ -651,7 +651,7 @@ pub mod os {
651651

652652
impl<T> fmt::Debug for Key<T> {
653653
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
654-
f.pad("Key { .. }")
654+
f.debug_struct("Key").finish_non_exhaustive()
655655
}
656656
}
657657

‎library/std/src/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
14131413
#[stable(feature = "std_debug", since = "1.16.0")]
14141414
impl<T> fmt::Debug for JoinHandle<T> {
14151415
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1416-
f.pad("JoinHandle { .. }")
1416+
f.debug_struct("JoinHandle").finish_non_exhaustive()
14171417
}
14181418
}
14191419

0 commit comments

Comments
 (0)
Please sign in to comment.