Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass fmt::Arguments by reference to PanicInfo and PanicMessage #129491

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Pass fmt::Arguments by reference to PanicInfo and PanicMessage
  • Loading branch information
StackOverflowExcept1on committed Aug 23, 2024
commit c2fdb3435fea8d30ef059dffd48332a537274005
12 changes: 6 additions & 6 deletions library/core/src/panic/panic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::panic::Location;
#[stable(feature = "panic_hooks", since = "1.10.0")]
#[derive(Debug)]
pub struct PanicInfo<'a> {
message: fmt::Arguments<'a>,
message: &'a fmt::Arguments<'a>,
location: &'a Location<'a>,
can_unwind: bool,
force_no_backtrace: bool,
Expand All @@ -26,13 +26,13 @@ pub struct PanicInfo<'a> {
/// See [`PanicInfo::message`].
#[stable(feature = "panic_info_message", since = "1.81.0")]
pub struct PanicMessage<'a> {
message: fmt::Arguments<'a>,
message: &'a fmt::Arguments<'a>,
}

impl<'a> PanicInfo<'a> {
#[inline]
pub(crate) fn new(
message: fmt::Arguments<'a>,
message: &'a fmt::Arguments<'a>,
location: &'a Location<'a>,
can_unwind: bool,
force_no_backtrace: bool,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Display for PanicInfo<'_> {
formatter.write_str("panicked at ")?;
self.location.fmt(formatter)?;
formatter.write_str(":\n")?;
formatter.write_fmt(self.message)?;
formatter.write_fmt(*self.message)?;
Ok(())
}
}
Expand Down Expand Up @@ -177,14 +177,14 @@ impl<'a> PanicMessage<'a> {
impl Display for PanicMessage<'_> {
#[inline]
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_fmt(self.message)
formatter.write_fmt(*self.message)
}
}

#[stable(feature = "panic_info_message", since = "1.81.0")]
impl fmt::Debug for PanicMessage<'_> {
#[inline]
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_fmt(self.message)
formatter.write_fmt(*self.message)
}
}
4 changes: 2 additions & 2 deletions library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
}

let pi = PanicInfo::new(
fmt,
&fmt,
Location::caller(),
/* can_unwind */ true,
/* force_no_backtrace */ false,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo

// PanicInfo with the `can_unwind` flag set to false forces an abort.
let pi = PanicInfo::new(
fmt,
&fmt,
Location::caller(),
/* can_unwind */ false,
force_no_backtrace,
Expand Down
Loading