From 84a367196019c16fa8d8a484c17804edc9a4af2e Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 10 Nov 2023 22:51:58 -0500 Subject: [PATCH] Panic directly in Arguments::new* instead of recursing --- library/core/src/fmt/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 287f6c23c899f..a971f33459ed1 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -328,7 +328,9 @@ impl<'a> Arguments<'a> { #[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")] pub const fn new_const(pieces: &'a [&'static str]) -> Self { if pieces.len() > 1 { - panic!("invalid args"); + // Since panic!() expands to panic_fmt(format_args!()), using the macro here is both a + // bit silly and also significantly increases the amount of MIR generated by panics. + crate::panicking::panic("invalid args"); } Arguments { pieces, fmt: None, args: &[] } } @@ -338,7 +340,8 @@ impl<'a> Arguments<'a> { #[inline] pub fn new_v1(pieces: &'a [&'static str], args: &'a [rt::Argument<'a>]) -> Arguments<'a> { if pieces.len() < args.len() || pieces.len() > args.len() + 1 { - panic!("invalid args"); + // See Arguments::new_const for why we don't use panic!. + crate::panicking::panic("invalid args"); } Arguments { pieces, fmt: None, args } }