Change Location<'_> lifetime to 'static in Panic[Hook]Info#146561
Change Location<'_> lifetime to 'static in Panic[Hook]Info#146561ijchen wants to merge 2 commits intorust-lang:mainfrom
Location<'_> lifetime to 'static in Panic[Hook]Info#146561Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
|
Considering that the only way to construct a location is |
4d90b34 to
e3b8df1
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
That's a great idea! I've updated accordingly. |
|
@rfcbot merge |
|
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
@Amanieu proposal cancelled. |
|
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
Friendly ping for checkboxes here, in case this slipped under the radar: @BurntSushi @joshtriplett @the8472 |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
|
So, I realize this is a bit late (sorry), but if we ever get the ability to remove the Location data to another file (debuginfo or similar, assuming a common separate-file-debuginfo paradigm), and then reconstruct the Location data on-the-spot, wouldn't acquiring a |
That's a great point, thanks for raising it. I do agree that promising a |
|
AIUI the idea is that panics might switch to not use |
|
Ahh I see - I think this is worth further discussion, what's the process for that? Is it too late to "cancel" the merge so we have more time to consider? |
|
I think that even in the case where location data is generated at runtime it can still be "leaked" to provide a static lifetime. This isn't a memory leak if we only do this once for each potential location. |
|
@Amanieu That is true in the sense that it will be at-worst linear in the number of |
|
A better question, perhaps: would providing a (way to get a) |
|
I like the idea of
That all said, I do think I'd rather force users to deal with a |
I'm writing a library that would benefit from being able to store a
&'static strinstead of aStringfor the file location of a panic. Currently, the API ofstd::panic::PanicHookInfo::locationandcore::panic::PanicInfo::locationreturn aLocation<'_>(and by extension, a file name&str) whose lifetime is tied to the borrow of thePanic[Hook]Info.It is my understanding that the
Location/&strwill always beLocation<'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'statichas a real benefit (allows users to avoid unnecessary allocations), I think changing to the returnedLocation<'_>'s lifetime to'staticwould be a worthwhile change.see also the recent #1320870, which made a similar change to
std::panic::Location