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 = "CURRENT_RUSTC_VERSION" ) ]
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 @@ -2669,22 +2669,12 @@ impl<T: Copy + Debug> Debug for Cell<T> {
2669
2669
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2670
2670
impl < T : ?Sized + Debug > Debug for RefCell < T > {
2671
2671
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2672
+ let mut d = f. debug_struct ( "RefCell" ) ;
2672
2673
match self . try_borrow ( ) {
2673
- Ok ( borrow) => f. debug_struct ( "RefCell" ) . field ( "value" , & borrow) . finish ( ) ,
2674
- Err ( _) => {
2675
- // The RefCell is mutably borrowed so we can't look at its value
2676
- // here. Show a placeholder instead.
2677
- struct BorrowedPlaceholder ;
2678
-
2679
- impl Debug for BorrowedPlaceholder {
2680
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2681
- f. write_str ( "<borrowed>" )
2682
- }
2683
- }
2684
-
2685
- f. debug_struct ( "RefCell" ) . field ( "value" , & BorrowedPlaceholder ) . finish ( )
2686
- }
2687
- }
2674
+ Ok ( borrow) => d. field ( "value" , & borrow) ,
2675
+ Err ( _) => d. field ( "value" , & format_args ! ( "<borrowed>" ) ) ,
2676
+ } ;
2677
+ d. finish ( )
2688
2678
}
2689
2679
}
2690
2680
Original file line number Diff line number Diff line change @@ -157,10 +157,12 @@ impl<T: Default> Default for LazyLock<T> {
157
157
#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
158
158
impl < T : fmt:: Debug , F > fmt:: Debug for LazyLock < T , F > {
159
159
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
160
+ let mut d = f. debug_tuple ( "LazyLock" ) ;
160
161
match self . get ( ) {
161
- Some ( v) => f. debug_tuple ( "LazyLock" ) . field ( v) . finish ( ) ,
162
- None => f. write_str ( "LazyLock(Uninit)" ) ,
163
- }
162
+ Some ( v) => d. field ( v) ,
163
+ None => d. field ( & format_args ! ( "<uninit>" ) ) ,
164
+ } ;
165
+ d. finish ( )
164
166
}
165
167
}
166
168
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 @@ -366,10 +366,12 @@ impl<T> const Default for OnceLock<T> {
366
366
#[ stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
367
367
impl < T : fmt:: Debug > fmt:: Debug for OnceLock < T > {
368
368
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
369
+ let mut d = f. debug_tuple ( "OnceLock" ) ;
369
370
match self . get ( ) {
370
- Some ( v) => f. debug_tuple ( "Once" ) . field ( v) . finish ( ) ,
371
- None => f. write_str ( "Once(Uninit)" ) ,
372
- }
371
+ Some ( v) => d. field ( v) ,
372
+ None => d. field ( & format_args ! ( "<uninit>" ) ) ,
373
+ } ;
374
+ d. finish ( )
373
375
}
374
376
}
375
377
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