This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +22
-38
lines changed Expand file tree Collapse file tree 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> {
250250#[ stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
251251impl < T : fmt:: Debug > fmt:: Debug for OnceCell < T > {
252252 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
253+ let mut d = f. debug_tuple ( "OnceCell" ) ;
253254 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 ( )
257259 }
258260}
259261
Original file line number Diff line number Diff line change @@ -2669,22 +2669,12 @@ impl<T: Copy + Debug> Debug for Cell<T> {
26692669#[ stable( feature = "rust1" , since = "1.0.0" ) ]
26702670impl < T : ?Sized + Debug > Debug for RefCell < T > {
26712671 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2672+ let mut d = f. debug_struct ( "RefCell" ) ;
26722673 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 ( )
26882678 }
26892679}
26902680
Original file line number Diff line number Diff line change @@ -157,10 +157,12 @@ impl<T: Default> Default for LazyLock<T> {
157157#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
158158impl < T : fmt:: Debug , F > fmt:: Debug for LazyLock < T , F > {
159159 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
160+ let mut d = f. debug_tuple ( "LazyLock" ) ;
160161 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 ( )
164166 }
165167}
166168
Original file line number Diff line number Diff line change @@ -490,13 +490,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
490490 d. field ( "data" , & & * * err. get_ref ( ) ) ;
491491 }
492492 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>" ) ) ;
500494 }
501495 }
502496 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> {
366366#[ stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
367367impl < T : fmt:: Debug > fmt:: Debug for OnceLock < T > {
368368 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
369+ let mut d = f. debug_tuple ( "OnceLock" ) ;
369370 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 ( )
373375 }
374376}
375377
Original file line number Diff line number Diff line change @@ -485,13 +485,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
485485 d. field ( "data" , & & * * err. get_ref ( ) ) ;
486486 }
487487 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>" ) ) ;
495489 }
496490 }
497491 d. field ( "poisoned" , & self . poison . get ( ) ) ;
You can’t perform that action at this time.
0 commit comments