From 4bbe532f3f5dbe849349966943024a7f31bf0adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 2 Oct 2025 23:18:04 +0000 Subject: [PATCH] More detail for `format!` `width` bigger than `u16::MAX` Formatting the width of a numeric value is limited to a `u16`, but the macros accept any `usize` and can panic at runtime. Previously the panic didn't provide any additional information about the failure, other than "too big". --- library/core/src/fmt/rt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index fb858a0572612..61e0f578c9e5e 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -150,7 +150,7 @@ impl Argument<'_> { #[track_caller] pub const fn from_usize(x: &usize) -> Argument<'_> { if *x > u16::MAX as usize { - panic!("Formatting argument out of range"); + panic!("Formatting argument out of range: `{x}` is bigger than `u16::MAX`"); } Argument { ty: ArgumentType::Count(*x as u16) } }