@@ -137,26 +137,43 @@ fn make_format_spec<'hir>(
137137 }
138138 Err ( _) => ctx. expr ( sp, hir:: ExprKind :: Err ) ,
139139 } ;
140- let fill = ctx. expr_char ( sp, placeholder. format_options . fill . unwrap_or ( ' ' ) ) ;
140+ let & FormatOptions {
141+ ref width,
142+ ref precision,
143+ alignment,
144+ fill,
145+ sign,
146+ alternate,
147+ zero_pad,
148+ debug_hex,
149+ } = & placeholder. format_options ;
150+ let fill = ctx. expr_char ( sp, fill. unwrap_or ( ' ' ) ) ;
141151 let align = ctx. expr_lang_item_type_relative (
142152 sp,
143153 hir:: LangItem :: FormatAlignment ,
144- match placeholder . format_options . alignment {
154+ match alignment {
145155 Some ( FormatAlignment :: Left ) => sym:: Left ,
146156 Some ( FormatAlignment :: Right ) => sym:: Right ,
147157 Some ( FormatAlignment :: Center ) => sym:: Center ,
148158 None => sym:: Unknown ,
149159 } ,
150160 ) ;
151- let flags = ctx. expr_u32 ( sp, placeholder. format_options . flags ) ;
152- let prec = make_count ( ctx, sp, & placeholder. format_options . precision , argmap) ;
153- let width = make_count ( ctx, sp, & placeholder. format_options . width , argmap) ;
161+ // This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
162+ let flags: u32 = ( ( sign == Some ( FormatSign :: Plus ) ) as u32 )
163+ | ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 1
164+ | ( alternate as u32 ) << 2
165+ | ( zero_pad as u32 ) << 3
166+ | ( ( debug_hex == Some ( FormatDebugHex :: Lower ) ) as u32 ) << 4
167+ | ( ( debug_hex == Some ( FormatDebugHex :: Upper ) ) as u32 ) << 5 ;
168+ let flags = ctx. expr_u32 ( sp, flags) ;
169+ let precision = make_count ( ctx, sp, & precision, argmap) ;
170+ let width = make_count ( ctx, sp, & width, argmap) ;
154171 let format_placeholder_new = ctx. arena . alloc ( ctx. expr_lang_item_type_relative (
155172 sp,
156173 hir:: LangItem :: FormatPlaceholder ,
157174 sym:: new,
158175 ) ) ;
159- let args = ctx. arena . alloc_from_iter ( [ position, fill, align, flags, prec , width] ) ;
176+ let args = ctx. arena . alloc_from_iter ( [ position, fill, align, flags, precision , width] ) ;
160177 ctx. expr_call_mut ( sp, format_placeholder_new, args)
161178}
162179
0 commit comments