Commit d77ab4f
committed
Auto merge of #146561 - ijchen:panic_location_static, r=Mark-Simulacrum
Change `Location<'_>` lifetime to `'static` in `Panic[Hook]Info`
I'm writing a library that would benefit from being able to store a `&'static str` instead of a `String` for the file location of a panic. Currently, the API of [`std::panic::PanicHookInfo::location`](https://doc.rust-lang.org/nightly/std/panic/struct.PanicHookInfo.html#method.location) and [`core::panic::PanicInfo::location`](https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html#method.location) return a `Location<'_>` (and by extension, a file name `&str`) whose lifetime is tied to the borrow of the `Panic[Hook]Info`.
It is my understanding that the `Location`/`&str` will always be `Location<'static>`/`&'static str`, since the file name is embedded directly into the compiled binary (and I don't see a likely reason/way for that to ever change in the future). Since it seems unlikely to ever need to change, and since making the guarantee that the returned lifetime is `'static` has a real benefit (allows users to avoid unnecessary allocations), I think changing to the returned `Location<'_>`'s lifetime to `'static` would be a worthwhile change.
see also the recent [#1320870](#132087), which made a similar change to [`std::panic::Location`](https://doc.rust-lang.org/nightly/std/panic/struct.Location.html)3 files changed
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
779 | | - | |
| 779 | + | |
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| |||
0 commit comments