Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eb0ed28
Remove usage of `isize` in example
tbu- May 28, 2024
1a840e7
Add test for incorrect pinning suggestion
estebank May 28, 2024
5585f31
Account for existing bindings when suggesting pinning
estebank May 28, 2024
69769fc
Expand list of trait implementers in E0277 when calling rustc with --…
lengrongfu Jun 6, 2024
3ba0262
CI: Update riscv64gc-linux job to 22.04, rename to riscv64gc-gnu
Hoverbear May 27, 2024
aafa93f
Move riscv64-gnu test out of disabled
Hoverbear May 29, 2024
f2e7d79
Add riscv64-gnu to PR tests
Hoverbear May 29, 2024
4c4eb39
Add workaround for git dubious ownership issue
Hoverbear May 31, 2024
e1b489d
Re-disable riscv64-gnu test
Hoverbear Jun 10, 2024
1462f3d
Add {{target}} substitution to compiletest
Veykril Jun 11, 2024
19a2dfe
Migrate `tests/run-make/prefer-dylib` to `rmake.rs`
GuillaumeGomez Jun 8, 2024
e3e8153
Split core's PanicInfo and std's PanicInfo.
m-ou-se Sep 19, 2023
a519dc8
Document difference between core and std's PanicInfo.
m-ou-se Sep 26, 2023
16dfc6d
Add core::panic::PanicInfo::payload() for compatibility.
m-ou-se Sep 26, 2023
331b8a3
Fix doc link.
m-ou-se Sep 26, 2023
83dd214
Update doc comment about core::panicking.
m-ou-se Oct 2, 2023
0266bbf
Remove core::panic::PanicInfo::internal_constructor.
m-ou-se Oct 2, 2023
0642cb2
Remove std::panic::PanicInfo::internal_constructor+set_payload.
m-ou-se Oct 2, 2023
0087d89
Mark some PanicInfo methods as #[inline] for consistency.
m-ou-se Oct 2, 2023
4e356f3
Move downcasting panic payload to str to a function.
m-ou-se Oct 2, 2023
22f7399
Use unnamed lifetimes for [..]Payload impl blocks.
m-ou-se Oct 2, 2023
1642de3
Impl Display for PanicPayload to simplify things.
m-ou-se Oct 2, 2023
bab26b0
Reorder body of begin_panic for consistency.
m-ou-se Oct 2, 2023
6b2d7c4
Fix invalid markdown/html.
m-ou-se Oct 2, 2023
b6180a9
Formatting.
m-ou-se Jan 31, 2024
64e56db
Rename std::panic::PanicInfo to PanicHookInfo.
m-ou-se Jan 31, 2024
3854357
Fix deprecation version.
m-ou-se Jan 31, 2024
f5fe82f
Move deprecation of std::panic::PanicInfo to 1.80.0.
m-ou-se Jan 31, 2024
ce0bc8b
Downcast panic payload to String too in example.
m-ou-se May 16, 2024
32bfe70
Add note on panic payload type.
m-ou-se May 16, 2024
877a26f
Mention core's PanicInfo in error.md.
m-ou-se May 16, 2024
fb0990d
Fix display of panic message in recursive panic.
m-ou-se May 16, 2024
de07c1a
Add PanicHookInfo::payload_as_str().
m-ou-se May 16, 2024
a345c3d
Bump deprecation of std's PanicInfo alias to 1.82.0.
m-ou-se May 16, 2024
a6e23b1
Formatting.
m-ou-se Jun 11, 2024
e45cfc7
Rollup merge of #115974 - m-ou-se:panicinfo-and-panicinfo, r=Amanieu
jieyouxu Jun 11, 2024
999ac87
Rollup merge of #125659 - tbu-:pr_rm_isize, r=pnkfelix
jieyouxu Jun 11, 2024
70aaf98
Rollup merge of #125669 - ferrocene:hoverbear/ci-docker-riscv64gc-upd…
jieyouxu Jun 11, 2024
1ca8f01
Rollup merge of #125684 - estebank:pin-to-binding-suggestion, r=pnkfelix
jieyouxu Jun 11, 2024
427429b
Rollup merge of #126055 - lengrongfu:master, r=pnkfelix
jieyouxu Jun 11, 2024
b1a88b8
Rollup merge of #126174 - GuillaumeGomez:migrate-run-make-prefer-dyli…
jieyouxu Jun 11, 2024
bc5bd47
Rollup merge of #126256 - ferrocene:lw-target-subst, r=albertlarsan68
jieyouxu Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Impl Display for PanicPayload to simplify things.
  • Loading branch information
m-ou-se committed Jun 11, 2024
commit 1642de33d3c4e59f3b4a766d0ad1abe046f0433f
2 changes: 1 addition & 1 deletion library/core/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub macro unreachable_2021 {
/// use.
#[unstable(feature = "std_internals", issue = "none")]
#[doc(hidden)]
pub unsafe trait PanicPayload {
pub unsafe trait PanicPayload: crate::fmt::Display {
/// Take full ownership of the contents.
/// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in core.
///
Expand Down
37 changes: 28 additions & 9 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,12 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
}
}

impl fmt::Display for FormatStringPayload<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(s) = &self.string { f.write_str(s) } else { f.write_fmt(*self.inner) }
}
}

struct StaticStrPayload(&'static str);

unsafe impl PanicPayload for StaticStrPayload {
Expand All @@ -637,21 +643,25 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
}
}

impl fmt::Display for StaticStrPayload {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.0)
}
}

let loc = info.location().unwrap(); // The current implementation always returns Some
let msg = info.message();
crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
if let Some(s) = msg.as_str() {
rust_panic_with_hook(
&mut StaticStrPayload(s),
Some(msg),
loc,
info.can_unwind(),
info.force_no_backtrace(),
);
} else {
rust_panic_with_hook(
&mut FormatStringPayload { inner: &msg, string: None },
Some(msg),
loc,
info.can_unwind(),
info.force_no_backtrace(),
Expand Down Expand Up @@ -681,7 +691,6 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
return crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
rust_panic_with_hook(
&mut Payload::new(msg),
None,
loc,
/* can_unwind */ true,
/* force_no_backtrace */ false,
Expand Down Expand Up @@ -719,6 +728,15 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
}
}
}

impl<A: Send + 'static> fmt::Display for Payload<A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
Some(a) => f.write_str(payload_as_str(a)),
None => process::abort(),
}
}
}
}

fn payload_as_str(payload: &dyn Any) -> &str {
Expand All @@ -738,7 +756,6 @@ fn payload_as_str(payload: &dyn Any) -> &str {
/// abort or unwind.
fn rust_panic_with_hook(
payload: &mut dyn PanicPayload,
message: Option<fmt::Arguments<'_>>,
location: &Location<'_>,
can_unwind: bool,
force_no_backtrace: bool,
Expand All @@ -765,11 +782,7 @@ fn rust_panic_with_hook(
panic_count::MustAbort::AlwaysAbort => {
// Unfortunately, this does not print a backtrace, because creating
// a `Backtrace` will allocate, which we must avoid here.
if let Some(message) = message {
rtprintpanic!("aborting due to panic at {location}:\n{message}\n");
} else {
rtprintpanic!("aborting due to panic at {location}\n");
}
rtprintpanic!("aborting due to panic at {location}:\n{payload}\n");
}
}
crate::sys::abort_internal();
Expand Down Expand Up @@ -825,6 +838,12 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
}
}

impl fmt::Display for RewrapBox {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(payload_as_str(&self.0))
}
}

rust_panic(&mut RewrapBox(payload))
}

Expand Down