Repository navigation
Tracking issue for PanicInfo::message #66745
Copy link
Copy link
Closed
Labels
A-error-handlingArea: Error handlingArea: Error handlingB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project group: Error handling (https://github.com/rust-lang/project-error-handling)T-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
#44489 was closed when #51366 stabilized the corresponding language feature, but we didn’t realize that it was also the tracking issue for this standard library feature:
// In `core::panic`:
impl PanicInfo<'_> {
/// The message that was given to the `panic!` macro.
pub fn message(&self) -> PanicMessage<'_>;
}
// Opaque type that wraps a fmt::Arguments<'a>.
pub struct PanicMessage<'a> { .. }
impl Display for PanicMessage<'_>;
impl Debug for PanicMessage<'_>;
impl PanicMessage<'_> {
pub fn as_str(&self) -> Option<&'static str>;
}History:
- Original tracking issue: Tracking issue for RFC 2070: stable mechanism to specify the behavior of panic! in no-std applications #44489
- Discussion of payload vs message Tracking issue for PanicInfo::message #66745 (comment)
- Making .message() infallible: Make
PanicInfo::messageinfallible #115561 - Split core/std PanicInfo into two types: Split core's PanicInfo and std's PanicInfo #115974
- This made core::panic::PanicInfo::message() infallible.
- Use opaque return type: Return opaque type from PanicInfo::message() #126330
- FCP
- Stablization PR: Stabilize
PanicInfo::message()andPanicMessage#126732
Unresolved questions:
- Should it be infallible?
- Yes, by making std::panic::PanicHookInfo a different type.
- What should the return type be?
fmt::Argumentsor an opaquePanicMessage? The first is simpler, but the latter allows a bit more flexibility for future changes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)Project group: Error handling (https://github.com/rust-lang/project-error-handling)T-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
SimonSapin commentedon Nov 25, 2019
Instead of making a PR go through the queue to fix the tracking issue, should we stabilize this method?
@rfcbot fcp merge
The doc-comment is slightly wrong or out of date. Its second line shoudl be removed.
core::panic!always creates aPanicInfowheremessageisSome, regardless of the number of arguments given. In the single-argument case, that argument is required to have type&str.At first returning
fmt::Argumentsseemed unusual to me and I considered that we could make the method returnOption<impl Display + 'a>instead, on the basis that calling itsDisplayimpl is almost the only useful thing to do with aArguments. ButArgumentshas been stable and documented as the return type offormat_args!(…)since 1.0.0, so maybe it’s fine.rfcbot commentedon Nov 25, 2019
[-]Tracking issue for PanicInfo::message[/-][+]Tracking issue for PanicInfo::message and core::panic[/+]SimonSapin commentedon Nov 25, 2019
The
core::panicmodule also links to that closed tracking issue. Let’s consider the pFCP above to also include stabilizing it. (std::panicis stable.)SimonSapin commentedon Nov 25, 2019
@rfcbot concern single-arg core::panic
Should we change libcore’s
panicmacro so that its single-argument form creates aPanicInfowith apayloadinstead of one with amessage? CC #66740 (comment)Pushing this idea further, it’s tempting to maybe remove
PanicInfo::messageentirely and instead have apayloadwhose dynamic type can befmt::Arguments. But that doesn’t work becausedowncast_refis a method ofdyn Any + 'staticandfmt::Arguments<'_>is not'static.sfackler commentedon Nov 25, 2019
I thought the point of the message field was that core can't make a payload since it can't allocate?
SimonSapin commentedon Nov 25, 2019
The struct is:
Both the
payloadandmessagefields involve borrowing. As far asPanicInfois concerned, they could both be borrowing form a stack frame. (And as far as I understand they are, in practice today.)It’s in the case of unwinding that there’s an owned
Box<dyn Any + Send>thatcatch_unwindcan return, which requires allocating.SimonSapin commentedon Nov 25, 2019
@RalfJung Based on the timing of https://www.ralfj.de/blog/2019/11/25/how-to-panic-in-rust.html it looks like you may have thoughts on this :)
SimonSapin commentedon Nov 25, 2019
Ah, https://www.ralfj.de/blog/2019/11/25/how-to-panic-in-rust.html goes into how and why the panic handler in libstd (which is called by
core::panic!if libstd is linked) ignores thepayloadit receives.We could probably change this but it gets tricky: while most implementations of
#[panic_handler]forno_stdenvironments would be fine with receiving a borrowed payload, libstd wants to potentially take ownership and box it for unwinding.alexcrichton commentedon Nov 25, 2019
I have zero recollection for why this is the way it is, and I'm not really particularly interested in doing all the archaeology to dig up why it is the way it is. I'm not a huge fan of just stabilizing things because they happen to be there, but I don't really see why we wouldn't want to stabilize this. If there were a reason to not stabilize this though an investigation would presumably turn that up, but I'm not up to do that investigation myself.
40 remaining items
rfcbot commentedon Jun 29, 2024
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.
Rollup merge of rust-lang#126732 - StackOverflowExcept1on:master, r=m…
Unrolled build for rust-lang#126732
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
Update platform010 & platform010-aarch64 symlinks
wasm: fix PanicMessage following rust-lang/rust#66745