Skip to content

Commit e3b8df1

Browse files
committed
updated returned Location references to 'static
1 parent b24b80c commit e3b8df1

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

library/core/src/panic/panic_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::panic::Location;
1313
#[derive(Debug)]
1414
pub struct PanicInfo<'a> {
1515
message: &'a fmt::Arguments<'a>,
16-
location: &'a Location<'static>,
16+
location: &'static Location<'static>,
1717
can_unwind: bool,
1818
force_no_backtrace: bool,
1919
}
@@ -33,7 +33,7 @@ impl<'a> PanicInfo<'a> {
3333
#[inline]
3434
pub(crate) fn new(
3535
message: &'a fmt::Arguments<'a>,
36-
location: &'a Location<'static>,
36+
location: &'static Location<'static>,
3737
can_unwind: bool,
3838
force_no_backtrace: bool,
3939
) -> Self {
@@ -88,10 +88,10 @@ impl<'a> PanicInfo<'a> {
8888
/// ```
8989
#[must_use]
9090
#[stable(feature = "panic_hooks", since = "1.10.0")]
91-
pub fn location(&self) -> Option<&Location<'static>> {
91+
pub fn location(&self) -> Option<&'static Location<'static>> {
9292
// NOTE: If this is changed to sometimes return None,
9393
// deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
94-
Some(&self.location)
94+
Some(self.location)
9595
}
9696

9797
/// Returns the payload associated with the panic.

library/std/src/panic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ pub type PanicInfo<'a> = PanicHookInfo<'a>;
4141
#[derive(Debug)]
4242
pub struct PanicHookInfo<'a> {
4343
payload: &'a (dyn Any + Send),
44-
location: &'a Location<'static>,
44+
location: &'static Location<'static>,
4545
can_unwind: bool,
4646
force_no_backtrace: bool,
4747
}
4848

4949
impl<'a> PanicHookInfo<'a> {
5050
#[inline]
5151
pub(crate) fn new(
52-
location: &'a Location<'static>,
52+
location: &'static Location<'static>,
5353
payload: &'a (dyn Any + Send),
5454
can_unwind: bool,
5555
force_no_backtrace: bool,
@@ -160,10 +160,10 @@ impl<'a> PanicHookInfo<'a> {
160160
#[must_use]
161161
#[inline]
162162
#[stable(feature = "panic_hooks", since = "1.10.0")]
163-
pub fn location(&self) -> Option<&Location<'static>> {
163+
pub fn location(&self) -> Option<&'static Location<'static>> {
164164
// NOTE: If this is changed to sometimes return None,
165165
// deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
166-
Some(&self.location)
166+
Some(self.location)
167167
}
168168

169169
/// Returns whether the panic handler is allowed to unwind the stack from

library/std/src/panicking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ fn payload_as_str(payload: &dyn Any) -> &str {
795795
#[optimize(size)]
796796
fn panic_with_hook(
797797
payload: &mut dyn PanicPayload,
798-
location: &Location<'static>,
798+
location: &'static Location<'static>,
799799
can_unwind: bool,
800800
force_no_backtrace: bool,
801801
) -> ! {

library/std/tests/panic.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![allow(dead_code)]
22

3-
use core::panic::PanicInfo;
43
use std::cell::RefCell;
5-
use std::panic::{AssertUnwindSafe, Location, PanicHookInfo, UnwindSafe};
4+
use std::panic::{AssertUnwindSafe, UnwindSafe};
65
use std::rc::Rc;
76
use std::sync::{Arc, Mutex, RwLock};
87

@@ -55,20 +54,3 @@ fn panic_safety_traits() {
5554
assert::<Arc<AssertUnwindSafe<T>>>();
5655
}
5756
}
58-
59-
#[test]
60-
fn panic_info_static_location<'x>() {
61-
// Verify that the returned `Location<'_>`s generic lifetime is 'static when
62-
// calling `PanicInfo::location`. Test failure is indicated by a compile
63-
// failure, not a runtime panic.
64-
let _: for<'a> fn(&'a PanicInfo<'x>) -> Option<&'a Location<'static>> = PanicInfo::location;
65-
}
66-
67-
#[test]
68-
fn panic_hook_info_static_location<'x>() {
69-
// Verify that the returned `Location<'_>`s generic lifetime is 'static when
70-
// calling `PanicHookInfo::location`. Test failure is indicated by a compile
71-
// failure, not a runtime panic.
72-
let _: for<'a> fn(&'a PanicHookInfo<'x>) -> Option<&'a Location<'static>> =
73-
PanicHookInfo::location;
74-
}

0 commit comments

Comments
 (0)