Pass fmt::Arguments
by reference to PanicInfo
and PanicMessage
This commit is contained in:
parent
eef00c8be8
commit
c2fdb3435f
@ -12,7 +12,7 @@ use crate::panic::Location;
|
|||||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PanicInfo<'a> {
|
pub struct PanicInfo<'a> {
|
||||||
message: fmt::Arguments<'a>,
|
message: &'a fmt::Arguments<'a>,
|
||||||
location: &'a Location<'a>,
|
location: &'a Location<'a>,
|
||||||
can_unwind: bool,
|
can_unwind: bool,
|
||||||
force_no_backtrace: bool,
|
force_no_backtrace: bool,
|
||||||
@ -26,13 +26,13 @@ pub struct PanicInfo<'a> {
|
|||||||
/// See [`PanicInfo::message`].
|
/// See [`PanicInfo::message`].
|
||||||
#[stable(feature = "panic_info_message", since = "1.81.0")]
|
#[stable(feature = "panic_info_message", since = "1.81.0")]
|
||||||
pub struct PanicMessage<'a> {
|
pub struct PanicMessage<'a> {
|
||||||
message: fmt::Arguments<'a>,
|
message: &'a fmt::Arguments<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PanicInfo<'a> {
|
impl<'a> PanicInfo<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
message: fmt::Arguments<'a>,
|
message: &'a fmt::Arguments<'a>,
|
||||||
location: &'a Location<'a>,
|
location: &'a Location<'a>,
|
||||||
can_unwind: bool,
|
can_unwind: bool,
|
||||||
force_no_backtrace: bool,
|
force_no_backtrace: bool,
|
||||||
@ -146,7 +146,7 @@ impl Display for PanicInfo<'_> {
|
|||||||
formatter.write_str("panicked at ")?;
|
formatter.write_str("panicked at ")?;
|
||||||
self.location.fmt(formatter)?;
|
self.location.fmt(formatter)?;
|
||||||
formatter.write_str(":\n")?;
|
formatter.write_str(":\n")?;
|
||||||
formatter.write_fmt(self.message)?;
|
formatter.write_fmt(*self.message)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ impl<'a> PanicMessage<'a> {
|
|||||||
impl Display for PanicMessage<'_> {
|
impl Display for PanicMessage<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
formatter.write_fmt(self.message)
|
formatter.write_fmt(*self.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +185,6 @@ impl Display for PanicMessage<'_> {
|
|||||||
impl fmt::Debug for PanicMessage<'_> {
|
impl fmt::Debug for PanicMessage<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
formatter.write_fmt(self.message)
|
formatter.write_fmt(*self.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let pi = PanicInfo::new(
|
let pi = PanicInfo::new(
|
||||||
fmt,
|
&fmt,
|
||||||
Location::caller(),
|
Location::caller(),
|
||||||
/* can_unwind */ true,
|
/* can_unwind */ true,
|
||||||
/* force_no_backtrace */ false,
|
/* force_no_backtrace */ false,
|
||||||
@ -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.
|
// PanicInfo with the `can_unwind` flag set to false forces an abort.
|
||||||
let pi = PanicInfo::new(
|
let pi = PanicInfo::new(
|
||||||
fmt,
|
&fmt,
|
||||||
Location::caller(),
|
Location::caller(),
|
||||||
/* can_unwind */ false,
|
/* can_unwind */ false,
|
||||||
force_no_backtrace,
|
force_no_backtrace,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user