Change Location<'_> lifetime to 'static in Panic[Hook]Info - #146561
Conversation
|
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 |
|
I found this PR after also writing some code that could've made good use of getting a If there's appetite for having an accessor that returns a More fundamentally: it's not clear to me why "no If you want that binary size benefit so badly, you're not going to ship debug info with the binary, you'll use split debug info, not ship the debug info with the binary, and do symbolication of crashes out-of-process (often on a different machine entirely). You may not even want to pay the cost of embedding symbolication code in the binary (cc #139209). So it seems unlikely that a binary built with the "panic Location opt-out" flag will be able to actually recover any locations. I only see two cases where the debug info would nevertheless be available, but neither seems convincing to me:
|
|
This was discussed in the @rust-lang/libs-api meeting. We stand by our previous decision to stabilize this change, essentially agreeing with @hanna-kruppe's assessment. @bors r+ |
|
📋 This PR cannot be approved because it currently has the following label: |
|
I believe this is now just waiting on code review, correct? |
|
pinging @Mark-Simulacrum as the current assignee - let me know if this is waiting on me for something, I'm new to the process. |
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
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)
|
💔 Test for d77ab4f failed: CI. Failed job:
|
|
@bors retry |
|
A job failed! Check out the build log: (web) (plain enhanced) (plain) Click to see the possible cause of the failure (guessed by this bot) |
Rollup 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)
View all comments
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