From 560b12d0948296d972a7bb3bfe144a16be0aa5b2 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 11 Nov 2025 17:17:23 +0100 Subject: [PATCH] Don't encode zero width or precision in fmt string. --- compiler/rustc_ast_lowering/src/format.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index d8a602c949a9..39e2630ed913 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -393,13 +393,19 @@ fn expand_format_args<'hir>( bytecode.extend_from_slice(&flags.to_le_bytes()); if let Some(val) = &o.width { let (indirect, val) = make_count(val, &mut argmap); - bytecode[i] |= 1 << 1 | (indirect as u8) << 4; - bytecode.extend_from_slice(&val.to_le_bytes()); + // Only encode if nonzero; zero is the default. + if indirect || val != 0 { + bytecode[i] |= 1 << 1 | (indirect as u8) << 4; + bytecode.extend_from_slice(&val.to_le_bytes()); + } } if let Some(val) = &o.precision { let (indirect, val) = make_count(val, &mut argmap); - bytecode[i] |= 1 << 2 | (indirect as u8) << 5; - bytecode.extend_from_slice(&val.to_le_bytes()); + // Only encode if nonzero; zero is the default. + if indirect || val != 0 { + bytecode[i] |= 1 << 2 | (indirect as u8) << 5; + bytecode.extend_from_slice(&val.to_le_bytes()); + } } } if implicit_arg_index != position {