@@ -361,24 +361,25 @@ fn make_format_spec<'hir>(
361
361
zero_pad,
362
362
debug_hex,
363
363
} = & placeholder. format_options ;
364
- let fill = ctx. expr_char ( sp, fill. unwrap_or ( ' ' ) ) ;
365
- let align = ctx. expr_lang_item_type_relative (
366
- sp,
367
- hir:: LangItem :: FormatAlignment ,
368
- match alignment {
369
- Some ( FormatAlignment :: Left ) => sym:: Left ,
370
- Some ( FormatAlignment :: Right ) => sym:: Right ,
371
- Some ( FormatAlignment :: Center ) => sym:: Center ,
372
- None => sym:: Unknown ,
373
- } ,
374
- ) ;
375
- // This needs to match `Flag` in library/core/src/fmt/rt.rs.
364
+ let fill = fill. unwrap_or ( ' ' ) ;
365
+ // These need to match the constants in library/core/src/fmt/rt.rs.
366
+ let align = match alignment {
367
+ Some ( FormatAlignment :: Left ) => 0 ,
368
+ Some ( FormatAlignment :: Right ) => 1 ,
369
+ Some ( FormatAlignment :: Center ) => 2 ,
370
+ None => 3 ,
371
+ } ;
372
+ // This needs to match the constants in library/core/src/fmt/rt.rs.
376
373
let flags: u32 = ( ( sign == Some ( FormatSign :: Plus ) ) as u32 )
377
374
| ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 1
378
375
| ( alternate as u32 ) << 2
379
376
| ( zero_pad as u32 ) << 3
380
377
| ( ( debug_hex == Some ( FormatDebugHex :: Lower ) ) as u32 ) << 4
381
- | ( ( debug_hex == Some ( FormatDebugHex :: Upper ) ) as u32 ) << 5 ;
378
+ | ( ( debug_hex == Some ( FormatDebugHex :: Upper ) ) as u32 ) << 5
379
+ | align << 6
380
+ | ( width. is_some ( ) as u32 ) << 8
381
+ | ( precision. is_some ( ) as u32 ) << 9
382
+ | ( fill as u32 ) << 11 ;
382
383
let flags = ctx. expr_u32 ( sp, flags) ;
383
384
let precision = make_count ( ctx, sp, precision, argmap) ;
384
385
let width = make_count ( ctx, sp, width, argmap) ;
@@ -387,7 +388,7 @@ fn make_format_spec<'hir>(
387
388
hir:: LangItem :: FormatPlaceholder ,
388
389
sym:: new,
389
390
) ) ;
390
- let args = ctx. arena . alloc_from_iter ( [ position, fill , align , flags, precision, width] ) ;
391
+ let args = ctx. arena . alloc_from_iter ( [ position, flags, precision, width] ) ;
391
392
ctx. expr_call_mut ( sp, format_placeholder_new, args)
392
393
}
393
394
0 commit comments