File tree 6 files changed +22
-38
lines changed
6 files changed +22
-38
lines changed Original file line number Diff line number Diff line change @@ -250,10 +250,12 @@ impl<T> Default for OnceCell<T> {
250
250
#[ stable( feature = "once_cell" , since = "1.70.0" ) ]
251
251
impl < T : fmt:: Debug > fmt:: Debug for OnceCell < T > {
252
252
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
253
+ let mut d = f. debug_tuple ( "OnceCell" ) ;
253
254
match self . get ( ) {
254
- Some ( v) => f. debug_tuple ( "OnceCell" ) . field ( v) . finish ( ) ,
255
- None => f. write_str ( "OnceCell(Uninit)" ) ,
256
- }
255
+ Some ( v) => d. field ( v) ,
256
+ None => d. field ( & format_args ! ( "<uninit>" ) ) ,
257
+ } ;
258
+ d. finish ( )
257
259
}
258
260
}
259
261
Original file line number Diff line number Diff line change @@ -2521,22 +2521,12 @@ impl<T: Copy + Debug> Debug for Cell<T> {
2521
2521
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2522
2522
impl < T : ?Sized + Debug > Debug for RefCell < T > {
2523
2523
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2524
+ let mut d = f. debug_struct ( "RefCell" ) ;
2524
2525
match self . try_borrow ( ) {
2525
- Ok ( borrow) => f. debug_struct ( "RefCell" ) . field ( "value" , & borrow) . finish ( ) ,
2526
- Err ( _) => {
2527
- // The RefCell is mutably borrowed so we can't look at its value
2528
- // here. Show a placeholder instead.
2529
- struct BorrowedPlaceholder ;
2530
-
2531
- impl Debug for BorrowedPlaceholder {
2532
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2533
- f. write_str ( "<borrowed>" )
2534
- }
2535
- }
2536
-
2537
- f. debug_struct ( "RefCell" ) . field ( "value" , & BorrowedPlaceholder ) . finish ( )
2538
- }
2539
- }
2526
+ Ok ( borrow) => d. field ( "value" , & borrow) ,
2527
+ Err ( _) => d. field ( "value" , & format_args ! ( "<borrowed>" ) ) ,
2528
+ } ;
2529
+ d. finish ( )
2540
2530
}
2541
2531
}
2542
2532
Original file line number Diff line number Diff line change @@ -222,10 +222,12 @@ impl<T: Default> Default for LazyLock<T> {
222
222
#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
223
223
impl < T : fmt:: Debug , F > fmt:: Debug for LazyLock < T , F > {
224
224
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
225
+ let mut d = f. debug_tuple ( "LazyLock" ) ;
225
226
match self . get ( ) {
226
- Some ( v) => f. debug_tuple ( "LazyLock" ) . field ( v) . finish ( ) ,
227
- None => f. write_str ( "LazyLock(Uninit)" ) ,
228
- }
227
+ Some ( v) => d. field ( v) ,
228
+ None => d. field ( & format_args ! ( "<uninit>" ) ) ,
229
+ } ;
230
+ d. finish ( )
229
231
}
230
232
}
231
233
Original file line number Diff line number Diff line change @@ -490,13 +490,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
490
490
d. field ( "data" , & & * * err. get_ref ( ) ) ;
491
491
}
492
492
Err ( TryLockError :: WouldBlock ) => {
493
- struct LockedPlaceholder ;
494
- impl fmt:: Debug for LockedPlaceholder {
495
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
496
- f. write_str ( "<locked>" )
497
- }
498
- }
499
- d. field ( "data" , & LockedPlaceholder ) ;
493
+ d. field ( "data" , & format_args ! ( "<locked>" ) ) ;
500
494
}
501
495
}
502
496
d. field ( "poisoned" , & self . poison . get ( ) ) ;
Original file line number Diff line number Diff line change @@ -365,10 +365,12 @@ impl<T> Default for OnceLock<T> {
365
365
#[ stable( feature = "once_cell" , since = "1.70.0" ) ]
366
366
impl < T : fmt:: Debug > fmt:: Debug for OnceLock < T > {
367
367
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
368
+ let mut d = f. debug_tuple ( "OnceLock" ) ;
368
369
match self . get ( ) {
369
- Some ( v) => f. debug_tuple ( "Once" ) . field ( v) . finish ( ) ,
370
- None => f. write_str ( "Once(Uninit)" ) ,
371
- }
370
+ Some ( v) => d. field ( v) ,
371
+ None => d. field ( & format_args ! ( "<uninit>" ) ) ,
372
+ } ;
373
+ d. finish ( )
372
374
}
373
375
}
374
376
Original file line number Diff line number Diff line change @@ -485,13 +485,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
485
485
d. field ( "data" , & & * * err. get_ref ( ) ) ;
486
486
}
487
487
Err ( TryLockError :: WouldBlock ) => {
488
- struct LockedPlaceholder ;
489
- impl fmt:: Debug for LockedPlaceholder {
490
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
491
- f. write_str ( "<locked>" )
492
- }
493
- }
494
- d. field ( "data" , & LockedPlaceholder ) ;
488
+ d. field ( "data" , & format_args ! ( "<locked>" ) ) ;
495
489
}
496
490
}
497
491
d. field ( "poisoned" , & self . poison . get ( ) ) ;
You can’t perform that action at this time.
0 commit comments