about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2023-01-27 11:43:38 +0100
committerMara Bos <m-ou.se@m-ou.se>2023-01-27 11:43:38 +0100
commit21cf9dbc8540656cb137ef31f9db8fd9f1398fd9 (patch)
tree5bfd8328582317d2e2b9ee7dc67b07086f64b596
parentbe69002dd704a918885de493355705a545fa908a (diff)
downloadrust-21cf9dbc8540656cb137ef31f9db8fd9f1398fd9.tar.gz
rust-21cf9dbc8540656cb137ef31f9db8fd9f1398fd9.zip
Destructure format_options in make_format_spec.
-rw-r--r--compiler/rustc_ast_lowering/src/format.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs
index 5d1770c734d..e7dd0b18a03 100644
--- a/compiler/rustc_ast_lowering/src/format.rs
+++ b/compiler/rustc_ast_lowering/src/format.rs
@@ -137,11 +137,21 @@ fn make_format_spec<'hir>(
         }
         Err(_) => ctx.expr(sp, hir::ExprKind::Err),
     };
-    let fill = ctx.expr_char(sp, placeholder.format_options.fill.unwrap_or(' '));
+    let &FormatOptions {
+        ref width,
+        ref precision,
+        alignment,
+        fill,
+        sign,
+        alternate,
+        zero_pad,
+        debug_hex,
+    } = &placeholder.format_options;
+    let fill = ctx.expr_char(sp, fill.unwrap_or(' '));
     let align = ctx.expr_lang_item_type_relative(
         sp,
         hir::LangItem::FormatAlignment,
-        match placeholder.format_options.alignment {
+        match alignment {
             Some(FormatAlignment::Left) => sym::Left,
             Some(FormatAlignment::Right) => sym::Right,
             Some(FormatAlignment::Center) => sym::Center,
@@ -149,21 +159,21 @@ fn make_format_spec<'hir>(
         },
     );
     // This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
-    let flags: u32 = ((placeholder.format_options.sign == Some(FormatSign::Plus)) as u32)
-        | ((placeholder.format_options.sign == Some(FormatSign::Minus)) as u32) << 1
-        | (placeholder.format_options.alternate as u32) << 2
-        | (placeholder.format_options.zero_pad as u32) << 3
-        | ((placeholder.format_options.debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
-        | ((placeholder.format_options.debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
+    let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
+        | ((sign == Some(FormatSign::Minus)) as u32) << 1
+        | (alternate as u32) << 2
+        | (zero_pad as u32) << 3
+        | ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
+        | ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
     let flags = ctx.expr_u32(sp, flags);
-    let prec = make_count(ctx, sp, &placeholder.format_options.precision, argmap);
-    let width = make_count(ctx, sp, &placeholder.format_options.width, argmap);
+    let precision = make_count(ctx, sp, &precision, argmap);
+    let width = make_count(ctx, sp, &width, argmap);
     let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
         sp,
         hir::LangItem::FormatPlaceholder,
         sym::new,
     ));
-    let args = ctx.arena.alloc_from_iter([position, fill, align, flags, prec, width]);
+    let args = ctx.arena.alloc_from_iter([position, fill, align, flags, precision, width]);
     ctx.expr_call_mut(sp, format_placeholder_new, args)
 }