Skip to content

Commit 21cf9db

Browse files
committed
Destructure format_options in make_format_spec.
1 parent be69002 commit 21cf9db

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

compiler/rustc_ast_lowering/src/format.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -137,33 +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
);
151161
// This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
152-
let flags: u32 = ((placeholder.format_options.sign == Some(FormatSign::Plus)) as u32)
153-
| ((placeholder.format_options.sign == Some(FormatSign::Minus)) as u32) << 1
154-
| (placeholder.format_options.alternate as u32) << 2
155-
| (placeholder.format_options.zero_pad as u32) << 3
156-
| ((placeholder.format_options.debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
157-
| ((placeholder.format_options.debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
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;
158168
let flags = ctx.expr_u32(sp, flags);
159-
let prec = make_count(ctx, sp, &placeholder.format_options.precision, argmap);
160-
let width = make_count(ctx, sp, &placeholder.format_options.width, argmap);
169+
let precision = make_count(ctx, sp, &precision, argmap);
170+
let width = make_count(ctx, sp, &width, argmap);
161171
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
162172
sp,
163173
hir::LangItem::FormatPlaceholder,
164174
sym::new,
165175
));
166-
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]);
167177
ctx.expr_call_mut(sp, format_placeholder_new, args)
168178
}
169179

0 commit comments

Comments
 (0)