Skip to content

Commit 7f848fb

Browse files
committed
Don't encode zero width or precision in fmt string.
1 parent 8af99df commit 7f848fb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,19 @@ fn expand_format_args<'hir>(
397397
bytecode.extend_from_slice(&flags.to_le_bytes());
398398
if let Some(val) = &o.width {
399399
let (indirect, val) = make_count(val, &mut argmap);
400-
bytecode[i] |= 1 << 1 | (indirect as u8) << 4;
401-
bytecode.extend_from_slice(&val.to_le_bytes());
400+
if indirect || val != 0 {
401+
// No need to encode zero; that's the default.
402+
bytecode[i] |= 1 << 1 | (indirect as u8) << 4;
403+
bytecode.extend_from_slice(&val.to_le_bytes());
404+
}
402405
}
403406
if let Some(val) = &o.precision {
404407
let (indirect, val) = make_count(val, &mut argmap);
405-
bytecode[i] |= 1 << 2 | (indirect as u8) << 5;
406-
bytecode.extend_from_slice(&val.to_le_bytes());
408+
if indirect || val != 0 {
409+
// No need to encode zero; that's the default.
410+
bytecode[i] |= 1 << 2 | (indirect as u8) << 5;
411+
bytecode.extend_from_slice(&val.to_le_bytes());
412+
}
407413
}
408414
}
409415
if implicit_arg_index != position {

0 commit comments

Comments
 (0)