Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7121f46

Browse files
committedApr 5, 2024
Auto merge of #117804 - saethlin:no-recursive-panics, r=<try>
Panic directly in Arguments::new* instead of recursing This has been bothering me because it looks very silly in MIR.
2 parents 5958f5e + 84a3671 commit 7121f46

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)
Failed to load comments.