Skip to content

Commit 84a3671

Browse files
committed
Panic directly in Arguments::new* instead of recursing
1 parent 5958f5e commit 84a3671

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/core/src/fmt/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ impl<'a> Arguments<'a> {
328328
#[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")]
329329
pub const fn new_const(pieces: &'a [&'static str]) -> Self {
330330
if pieces.len() > 1 {
331-
panic!("invalid args");
331+
// Since panic!() expands to panic_fmt(format_args!()), using the macro here is both a
332+
// bit silly and also significantly increases the amount of MIR generated by panics.
333+
crate::panicking::panic("invalid args");
332334
}
333335
Arguments { pieces, fmt: None, args: &[] }
334336
}
@@ -338,7 +340,8 @@ impl<'a> Arguments<'a> {
338340
#[inline]
339341
pub fn new_v1(pieces: &'a [&'static str], args: &'a [rt::Argument<'a>]) -> Arguments<'a> {
340342
if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
341-
panic!("invalid args");
343+
// See Arguments::new_const for why we don't use panic!.
344+
crate::panicking::panic("invalid args");
342345
}
343346
Arguments { pieces, fmt: None, args }
344347
}

0 commit comments

Comments
 (0)