Skip to content

Commit bff3625

Browse files
committed
panic_nounwind in Arguments::new* instead of recursing
1 parent 39e02f1 commit bff3625

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

library/core/src/fmt/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ impl<'a> Arguments<'a> {
340340
#[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")]
341341
pub const fn new_const(pieces: &'a [&'static str]) -> Self {
342342
if pieces.len() > 1 {
343-
panic!("invalid args");
343+
// Since panic!() expands to panic_fmt(format_args!()), using panic! here is both a
344+
// bit silly and also significantly increases the amount of MIR generated by panics.
345+
crate::panicking::panic_nounwind("invalid args");
344346
}
345347
Arguments { pieces, fmt: None, args: &[] }
346348
}
@@ -350,7 +352,8 @@ impl<'a> Arguments<'a> {
350352
#[inline]
351353
pub fn new_v1(pieces: &'a [&'static str], args: &'a [rt::Argument<'a>]) -> Arguments<'a> {
352354
if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
353-
panic!("invalid args");
355+
// See Arguments::new_const for why we don't use panic!.
356+
crate::panicking::panic_nounwind("invalid args");
354357
}
355358
Arguments { pieces, fmt: None, args }
356359
}

0 commit comments

Comments
 (0)