Change Location<'_> lifetime to 'static in Panic[Hook]Info by ijchen · Pull Request #146561 · rust-lang/rust (original) (raw)
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 and core::panic::PanicInfo::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, which made a similar change to std::panic::Location