@@ -208,7 +208,11 @@ macro_rules! impl_Display {
208208            fn  fmt( & self ,  f:  & mut  fmt:: Formatter <' _>)  -> fmt:: Result  { 
209209                #[ cfg( not( feature = "optimize_for_size" ) ) ] 
210210                { 
211-                     self . _fmt( true ,  f) 
211+                     const  MAX_DEC_N :  usize  = $unsigned:: MAX . ilog( 10 )  as  usize  + 1 ; 
212+                     // Buffer decimals for $unsigned with right alignment. 
213+                     let  mut  buf = [ MaybeUninit :: <u8 >:: uninit( ) ;  MAX_DEC_N ] ; 
214+ 
215+                     f. pad_integral( true ,  "" ,  self . _fmt( & mut  buf) ) 
212216                } 
213217                #[ cfg( feature = "optimize_for_size" ) ] 
214218                { 
@@ -222,7 +226,11 @@ macro_rules! impl_Display {
222226            fn  fmt( & self ,  f:  & mut  fmt:: Formatter <' _>)  -> fmt:: Result  { 
223227                #[ cfg( not( feature = "optimize_for_size" ) ) ] 
224228                { 
225-                     return  self . unsigned_abs( ) . _fmt( * self  >= 0 ,  f) ; 
229+                     const  MAX_DEC_N :  usize  = $unsigned:: MAX . ilog( 10 )  as  usize  + 1 ; 
230+                     // Buffer decimals for $unsigned with right alignment. 
231+                     let  mut  buf = [ MaybeUninit :: <u8 >:: uninit( ) ;  MAX_DEC_N ] ; 
232+ 
233+                     f. pad_integral( * self  >= 0 ,  "" ,  self . unsigned_abs( ) . _fmt( & mut  buf) ) 
226234                } 
227235                #[ cfg( feature = "optimize_for_size" ) ] 
228236                { 
@@ -233,10 +241,13 @@ macro_rules! impl_Display {
233241
234242        #[ cfg( not( feature = "optimize_for_size" ) ) ] 
235243        impl  $unsigned { 
236-             fn  _fmt( self ,  is_nonnegative:  bool ,  f:  & mut  fmt:: Formatter <' _>)  -> fmt:: Result  { 
237-                 const  MAX_DEC_N :  usize  = $unsigned:: MAX . ilog( 10 )  as  usize  + 1 ; 
238-                 // Buffer decimals for $unsigned with right alignment. 
239-                 let  mut  buf = [ MaybeUninit :: <u8 >:: uninit( ) ;  MAX_DEC_N ] ; 
244+             #[ doc( hidden) ] 
245+             #[ unstable( 
246+                 feature = "fmt_internals" , 
247+                 reason = "specialized method meant to only be used by `SpecToString` implementation" , 
248+                 issue = "none" 
249+             ) ] 
250+             pub  fn  _fmt<' a>( self ,  buf:  & ' a mut  [ MaybeUninit :: <u8 >] )  -> & ' a str  { 
240251                // Count the number of bytes in buf that are not initialized. 
241252                let  mut  offset = buf. len( ) ; 
242253                // Consume the least-significant decimals from a working copy. 
@@ -301,13 +312,12 @@ macro_rules! impl_Display {
301312                // SAFETY: All buf content since offset is set. 
302313                let  written = unsafe  {  buf. get_unchecked( offset..)  } ; 
303314                // SAFETY: Writes use ASCII from the lookup table exclusively. 
304-                 let  as_str =  unsafe  { 
315+                 unsafe  { 
305316                    str :: from_utf8_unchecked( slice:: from_raw_parts( 
306317                          MaybeUninit :: slice_as_ptr( written) , 
307318                          written. len( ) , 
308319                    ) ) 
309-                 } ; 
310-                 f. pad_integral( is_nonnegative,  "" ,  as_str) 
320+                 } 
311321            } 
312322        } ) * 
313323
0 commit comments