diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index 9d53567a26fd9..ee22521cb014c 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -13,7 +13,7 @@ use crate::panic::Location; #[derive(Debug)] pub struct PanicInfo<'a> { message: &'a fmt::Arguments<'a>, - location: &'a Location<'a>, + location: &'static Location<'static>, can_unwind: bool, force_no_backtrace: bool, } @@ -33,7 +33,7 @@ impl<'a> PanicInfo<'a> { #[inline] pub(crate) fn new( message: &'a fmt::Arguments<'a>, - location: &'a Location<'a>, + location: &'static Location<'static>, can_unwind: bool, force_no_backtrace: bool, ) -> Self { @@ -88,10 +88,10 @@ impl<'a> PanicInfo<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn location(&self) -> Option<&Location<'_>> { + pub fn location(&self) -> Option<&'static Location<'static>> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. - Some(&self.location) + Some(self.location) } /// Returns the payload associated with the panic. diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 5e8d2f8e78ec7..13be7371c2329 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -41,7 +41,7 @@ pub type PanicInfo<'a> = PanicHookInfo<'a>; #[derive(Debug)] pub struct PanicHookInfo<'a> { payload: &'a (dyn Any + Send), - location: &'a Location<'a>, + location: &'static Location<'static>, can_unwind: bool, force_no_backtrace: bool, } @@ -49,7 +49,7 @@ pub struct PanicHookInfo<'a> { impl<'a> PanicHookInfo<'a> { #[inline] pub(crate) fn new( - location: &'a Location<'a>, + location: &'static Location<'static>, payload: &'a (dyn Any + Send), can_unwind: bool, force_no_backtrace: bool, @@ -160,10 +160,10 @@ impl<'a> PanicHookInfo<'a> { #[must_use] #[inline] #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn location(&self) -> Option<&Location<'_>> { + pub fn location(&self) -> Option<&'static Location<'static>> { // NOTE: If this is changed to sometimes return None, // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. - Some(&self.location) + Some(self.location) } /// Returns whether the panic handler is allowed to unwind the stack from diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 8b7282c51d123..e489d0f9f807e 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -795,7 +795,7 @@ fn payload_as_str(payload: &dyn Any) -> &str { #[optimize(size)] fn panic_with_hook( payload: &mut dyn PanicPayload, - location: &Location<'_>, + location: &'static Location<'static>, can_unwind: bool, force_no_backtrace: bool, ) -> ! {