diff options
| author | Ben Kimock <kimockb@gmail.com> | 2023-11-10 22:51:58 -0500 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2024-05-23 09:21:21 -0400 |
| commit | 75f3cef756afa4ae5d8b9c9e6b52124701c2285b (patch) | |
| tree | 54ea86aa6186dcbe8ef622d3f0f8e3760bb24144 | |
| parent | 39e02f1bd1e53d009da382654139f7c0639172a8 (diff) | |
panic_nounwind in Arguments::new* instead of recursing
| -rw-r--r-- | library/core/src/fmt/mod.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 9b372eac524..60a27863413 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -340,7 +340,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 panic! here is both a + // bit silly and also significantly increases the amount of MIR generated by panics. + crate::panicking::panic_nounwind("invalid args"); } Arguments { pieces, fmt: None, args: &[] } } @@ -350,7 +352,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_nounwind("invalid args"); } Arguments { pieces, fmt: None, args } } |
