about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-11-25 12:16:08 +0100
committerRalf Jung <post@ralfj.de>2019-11-25 12:16:08 +0100
commit08f779cb4b481be58eeb5ecc421f69503780e8b1 (patch)
tree95896dbd33e56152d8f42a065317b70f7a3f5aff
parentcd5d0c7b102d2573165efdbd2ffc31c4a5be3bb5 (diff)
downloadrust-08f779cb4b481be58eeb5ecc421f69503780e8b1.tar.gz
rust-08f779cb4b481be58eeb5ecc421f69503780e8b1.zip
better comment and rename BoxMeUp::box_me_up to take_box
-rw-r--r--src/libcore/panic.rs4
-rw-r--r--src/libpanic_unwind/lib.rs2
-rw-r--r--src/libstd/panicking.rs9
3 files changed, 9 insertions, 6 deletions
diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs
index cdd38449a1b..0abc481f6e5 100644
--- a/src/libcore/panic.rs
+++ b/src/libcore/panic.rs
@@ -266,6 +266,8 @@ impl fmt::Display for Location<'_> {
 #[unstable(feature = "std_internals", issue = "0")]
 #[doc(hidden)]
 pub unsafe trait BoxMeUp {
-    fn box_me_up(&mut self) -> *mut (dyn Any + Send);
+    /// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in libcore.
+    /// After this method got called, only some dummy default value is left in `self`.
+    fn take_box(&mut self) -> *mut (dyn Any + Send);
     fn get(&mut self) -> &(dyn Any + Send);
 }
diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs
index d97a7a8a87d..0c834e5c2a0 100644
--- a/src/libpanic_unwind/lib.rs
+++ b/src/libpanic_unwind/lib.rs
@@ -94,5 +94,5 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
 #[unwind(allowed)]
 pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
     let payload = payload as *mut &mut dyn BoxMeUp;
-    imp::panic(Box::from_raw((*payload).box_me_up()))
+    imp::panic(Box::from_raw((*payload).take_box()))
 }
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index a0f6183d514..a16eec45b9a 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -340,6 +340,7 @@ fn panic_handler(info: &PanicInfo<'_>) -> ! {
             use crate::fmt::Write;
 
             let inner = self.inner;
+            // Lazily, the first time this gets called, run the actual string formatting.
             self.string.get_or_insert_with(|| {
                 let mut s = String::new();
                 drop(s.write_fmt(*inner));
@@ -349,7 +350,7 @@ fn panic_handler(info: &PanicInfo<'_>) -> ! {
     }
 
     unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
-        fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
+        fn take_box(&mut self) -> *mut (dyn Any + Send) {
             let contents = mem::take(self.fill());
             Box::into_raw(Box::new(contents))
         }
@@ -407,10 +408,10 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3
     }
 
     unsafe impl<A: Send + 'static> BoxMeUp for PanicPayload<A> {
-        fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
+        fn take_box(&mut self) -> *mut (dyn Any + Send) {
             let data = match self.inner.take() {
                 Some(a) => Box::new(a) as Box<dyn Any + Send>,
-                None => Box::new(()),
+                None => Box::new(()), // this should never happen: we got called twice
             };
             Box::into_raw(data)
         }
@@ -488,7 +489,7 @@ pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! {
     struct RewrapBox(Box<dyn Any + Send>);
 
     unsafe impl BoxMeUp for RewrapBox {
-        fn box_me_up(&mut self) -> *mut (dyn Any + Send) {
+        fn take_box(&mut self) -> *mut (dyn Any + Send) {
             Box::into_raw(mem::replace(&mut self.0, Box::new(())))
         }