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 = "1.70.0" ) ]
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 @@ -2521,22 +2521,12 @@ impl<T: Copy + Debug> Debug for Cell<T> {
25212521#[ stable( feature = "rust1" , since = "1.0.0" ) ]
25222522impl < T : ?Sized + Debug > Debug for RefCell < T > {
25232523 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2524+ let mut d = f. debug_struct ( "RefCell" ) ;
25242525 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 ( )
25402530 }
25412531}
25422532
Original file line number Diff line number Diff line change @@ -222,10 +222,12 @@ impl<T: Default> Default for LazyLock<T> {
222222#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
223223impl < T : fmt:: Debug , F > fmt:: Debug for LazyLock < T , F > {
224224 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
225+ let mut d = f. debug_tuple ( "LazyLock" ) ;
225226 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 ( )
229231 }
230232}
231233
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 @@ -365,10 +365,12 @@ impl<T> Default for OnceLock<T> {
365365#[ stable( feature = "once_cell" , since = "1.70.0" ) ]
366366impl < T : fmt:: Debug > fmt:: Debug for OnceLock < T > {
367367 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
368+ let mut d = f. debug_tuple ( "OnceLock" ) ;
368369 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 ( )
372374 }
373375}
374376
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