Skip to content

Commit

Permalink
Panic directly in Arguments::new* instead of recursing
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Apr 5, 2024
1 parent 5958f5e commit 84a3671
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: &[] }
}
Expand All @@ -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 }
}
Expand Down

0 comments on commit 84a3671

Please sign in to comment.