@@ -361,24 +361,26 @@ 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.
376
- let flags: u32 = ( ( sign == Some ( FormatSign :: Plus ) ) as u32 )
377
- | ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 1
378
- | ( alternate as u32 ) << 2
379
- | ( zero_pad as u32 ) << 3
380
- | ( ( debug_hex == Some ( FormatDebugHex :: Lower ) ) as u32 ) << 4
381
- | ( ( debug_hex == Some ( FormatDebugHex :: Upper ) ) as u32 ) << 5 ;
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.
373
+ let flags: u32 = fill as u32
374
+ | ( ( sign == Some ( FormatSign :: Plus ) ) as u32 ) << 21
375
+ | ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 22
376
+ | ( alternate as u32 ) << 23
377
+ | ( zero_pad as u32 ) << 24
378
+ | ( ( debug_hex == Some ( FormatDebugHex :: Lower ) ) as u32 ) << 25
379
+ | ( ( debug_hex == Some ( FormatDebugHex :: Upper ) ) as u32 ) << 26
380
+ | ( width. is_some ( ) as u32 ) << 27
381
+ | ( precision. is_some ( ) as u32 ) << 28
382
+ | align << 29
383
+ | 1 << 31 ; // Highest bit always set.
382
384
let flags = ctx. expr_u32 ( sp, flags) ;
383
385
let precision = make_count ( ctx, sp, precision, argmap) ;
384
386
let width = make_count ( ctx, sp, width, argmap) ;
@@ -387,7 +389,7 @@ fn make_format_spec<'hir>(
387
389
hir:: LangItem :: FormatPlaceholder ,
388
390
sym:: new,
389
391
) ) ;
390
- let args = ctx. arena . alloc_from_iter ( [ position, fill , align , flags, precision, width] ) ;
392
+ let args = ctx. arena . alloc_from_iter ( [ position, flags, precision, width] ) ;
391
393
ctx. expr_call_mut ( sp, format_placeholder_new, args)
392
394
}
393
395
0 commit comments