From d4b7304c0de1857becdb679cb4db476771ce321e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 2 Oct 2023 14:29:58 +0200 Subject: [PATCH] Reorder body of begin_panic for consistency. 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. --- std/src/panicking.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/std/src/panicking.rs b/std/src/panicking.rs index 362aa8d06f33b..15544de9ff81f 100644 --- a/std/src/panicking.rs +++ b/std/src/panicking.rs @@ -687,26 +687,10 @@ pub const fn begin_panic(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 { inner: Option, } - impl Payload { - fn new(inner: A) -> Payload { - Payload { inner: Some(inner) } - } - } - unsafe impl PanicPayload for Payload { fn take_box(&mut self) -> *mut (dyn Any + Send) { // Note that this should be the only allocation performed in this code path. Currently @@ -729,7 +713,7 @@ pub const fn begin_panic(msg: M) -> ! { } } - impl fmt::Display for Payload { + impl fmt::Display for Payload { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.inner { Some(a) => f.write_str(payload_as_str(a)), @@ -737,6 +721,16 @@ pub const fn begin_panic(msg: M) -> ! { } } } + + 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 {