@@ -207,7 +207,10 @@ macro_rules! impl_Display {
207207 fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
208208 #[ cfg( not( feature = "optimize_for_size" ) ) ]
209209 {
210- self . _fmt( true , f)
210+ const SIZE : usize = $unsigned:: MAX . ilog( 10 ) as usize + 1 ;
211+ let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
212+
213+ f. pad_integral( true , "" , self . _fmt( & mut buf, SIZE ) )
211214 }
212215 #[ cfg( feature = "optimize_for_size" ) ]
213216 {
@@ -221,7 +224,10 @@ macro_rules! impl_Display {
221224 fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
222225 #[ cfg( not( feature = "optimize_for_size" ) ) ]
223226 {
224- return self . unsigned_abs( ) . _fmt( * self >= 0 , f) ;
227+ const SIZE : usize = $signed:: MAX . ilog( 10 ) as usize + 1 ;
228+ let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
229+
230+ f. pad_integral( * self >= 0 , "" , self . unsigned_abs( ) . _fmt( & mut buf, SIZE ) )
225231 }
226232 #[ cfg( feature = "optimize_for_size" ) ]
227233 {
@@ -232,11 +238,14 @@ macro_rules! impl_Display {
232238
233239 #[ cfg( not( feature = "optimize_for_size" ) ) ]
234240 impl $unsigned {
235- fn _fmt( mut self , is_nonnegative: bool , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
236- const SIZE : usize = $unsigned:: MAX . ilog( 10 ) as usize + 1 ;
237- let mut buf = [ MaybeUninit :: <u8 >:: uninit( ) ; SIZE ] ;
238- let mut curr = SIZE ;
239- let buf_ptr = MaybeUninit :: slice_as_mut_ptr( & mut buf) ;
241+ #[ doc( hidden) ]
242+ #[ unstable(
243+ feature = "fmt_internals" ,
244+ reason = "internal routines only exposed for testing" ,
245+ issue = "none"
246+ ) ]
247+ pub fn _fmt<' a>( mut self , buf: & ' a mut [ MaybeUninit :: <u8 >] , mut curr: usize ) -> & ' a str {
248+ let buf_ptr = MaybeUninit :: slice_as_mut_ptr( buf) ;
240249 let lut_ptr = DEC_DIGITS_LUT . as_ptr( ) ;
241250
242251 // SAFETY: Since `d1` and `d2` are always less than or equal to `198`, we
@@ -296,11 +305,10 @@ macro_rules! impl_Display {
296305
297306 // SAFETY: `curr` > 0 (since we made `buf` large enough), and all the chars are valid
298307 // UTF-8 since `DEC_DIGITS_LUT` is
299- let buf_slice = unsafe {
308+ unsafe {
300309 str :: from_utf8_unchecked(
301310 slice:: from_raw_parts( buf_ptr. add( curr) , buf. len( ) - curr) )
302- } ;
303- f. pad_integral( is_nonnegative, "" , buf_slice)
311+ }
304312 }
305313 } ) *
306314
0 commit comments