Skip to content

Commit 606afbb

Browse files
committed
Auto merge of #117804 - saethlin:no-recursive-panics, r=joboet
Panic directly in Arguments::new* instead of recursing This has been bothering me because it looks very silly in MIR.
2 parents 9c8a58f + 75f3cef commit 606afbb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: 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)