Skip to content

Commit 08f779c

Browse files
committed
better comment and rename BoxMeUp::box_me_up to take_box
1 parent cd5d0c7 commit 08f779c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/libcore/panic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ impl fmt::Display for Location<'_> {
266266
#[unstable(feature = "std_internals", issue = "0")]
267267
#[doc(hidden)]
268268
pub unsafe trait BoxMeUp {
269-
fn box_me_up(&mut self) -> *mut (dyn Any + Send);
269+
/// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in libcore.
270+
/// After this method got called, only some dummy default value is left in `self`.
271+
fn take_box(&mut self) -> *mut (dyn Any + Send);
270272
fn get(&mut self) -> &(dyn Any + Send);
271273
}

src/libpanic_unwind/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
9494
#[unwind(allowed)]
9595
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
9696
let payload = payload as *mut &mut dyn BoxMeUp;
97-
imp::panic(Box::from_raw((*payload).box_me_up()))
97+
imp::panic(Box::from_raw((*payload).take_box()))
9898
}

src/libstd/panicking.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ fn panic_handler(info: &PanicInfo<'_>) -> ! {
340340
use crate::fmt::Write;
341341

342342
let inner = self.inner;
343+
// Lazily, the first time this gets called, run the actual string formatting.
343344
self.string.get_or_insert_with(|| {
344345
let mut s = String::new();
345346
drop(s.write_fmt(*inner));
@@ -349,7 +350,7 @@ fn panic_handler(info: &PanicInfo<'_>) -> ! {
349350
}
350351

351352
unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
352-
fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
353+
fn take_box(&mut self) -> *mut (dyn Any + Send) {
353354
let contents = mem::take(self.fill());
354355
Box::into_raw(Box::new(contents))
355356
}
@@ -407,10 +408,10 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
407408
}
408409

409410
unsafe impl<A: Send + 'static> BoxMeUp for PanicPayload<A> {
410-
fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
411+
fn take_box(&mut self) -> *mut (dyn Any + Send) {
411412
let data = match self.inner.take() {
412413
Some(a) => Box::new(a) as Box<dyn Any + Send>,
413-
None => Box::new(()),
414+
None => Box::new(()), // this should never happen: we got called twice
414415
};
415416
Box::into_raw(data)
416417
}
@@ -488,7 +489,7 @@ pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! {
488489
struct RewrapBox(Box<dyn Any + Send>);
489490

490491
unsafe impl BoxMeUp for RewrapBox {
491-
fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
492+
fn take_box(&mut self) -> *mut (dyn Any + Send) {
492493
Box::into_raw(mem::replace(&mut self.0, Box::new(())))
493494
}
494495

0 commit comments

Comments
 (0)