Skip to content

Commit

Permalink
Reorder body of begin_panic for consistency.
Browse files Browse the repository at this point in the history
In the other functions, we put the struct and impl blocks first,
such that the return expression can be at the end of the body as usual.
  • Loading branch information
m-ou-se committed Jun 11, 2024
1 parent 373fb60 commit d4b7304
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,26 +687,10 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
intrinsics::abort()
}

let loc = Location::caller();
return crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
rust_panic_with_hook(
&mut Payload::new(msg),
loc,
/* can_unwind */ true,
/* force_no_backtrace */ false,
)
});

struct Payload<A> {
inner: Option<A>,
}

impl<A: Send + 'static> Payload<A> {
fn new(inner: A) -> Payload<A> {
Payload { inner: Some(inner) }
}
}

unsafe impl<A: Send + 'static> PanicPayload for Payload<A> {
fn take_box(&mut self) -> *mut (dyn Any + Send) {
// Note that this should be the only allocation performed in this code path. Currently
Expand All @@ -729,14 +713,24 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
}
}

impl<A: Send + 'static> fmt::Display for Payload<A> {
impl<A: '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(),
}
}
}

let loc = Location::caller();
crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
rust_panic_with_hook(
&mut Payload { inner: Some(msg) },
loc,
/* can_unwind */ true,
/* force_no_backtrace */ false,
)
})
}

fn payload_as_str(payload: &dyn Any) -> &str {
Expand Down

0 comments on commit d4b7304

Please sign in to comment.