diff --git a/src/panic-implementation.md b/src/panic-implementation.md index 4f4fb1a9..b62e2643 100644 --- a/src/panic-implementation.md +++ b/src/panic-implementation.md @@ -4,7 +4,8 @@ There are actually two panic macros - one defined in `libcore`, and one defined in `libstd`. This is due to the fact that code in `libcore` can panic. `libcore` is built before `libstd`, -but we want panics to use the same machinery at runtime, whether they originate in `libcore` or `libstd`. +but we want panics to use the same machinery at runtime, whether they originate in `libcore` +or `libstd`. ##### libcore definition of panic! @@ -65,12 +66,14 @@ we call ```__rust_start_panic```, which is provided by the panic runtime. The call to ```__rust_start_panic``` is very weird - it is passed a ```*mut &mut dyn BoxMeUp```, converted to an `usize`. Let's break this type down: -1. `BoxMeUp` is an internal trait. It is implemented for `PanicPayload` (a wrapper around the user-supplied -payload type), and has a method ```fn box_me_up(&mut self) -> *mut (dyn Any + Send)```. +1. `BoxMeUp` is an internal trait. It is implemented for `PanicPayload` +(a wrapper around the user-supplied payload type), and has a method +```fn box_me_up(&mut self) -> *mut (dyn Any + Send)```. This method takes the user-provided payload (`T: Any + Send`), boxes it, and convertes the box to a raw pointer. -2. When we call ```__rust_start_panic```, we have an `&mut dyn BoxMeUp`. However, this is a fat pointer -(twice the size of a `usize`). To pass this to the panic runtime across an FFI boundary, we take a mutable +2. When we call ```__rust_start_panic```, we have an `&mut dyn BoxMeUp`. +However, this is a fat pointer (twice the size of a `usize`). +To pass this to the panic runtime across an FFI boundary, we take a mutable reference *to this mutable reference* (`&mut &mut dyn BoxMeUp`), and convert it to a raw pointer (`*mut &mut dyn BoxMeUp`). The outer raw pointer is a thin pointer, since it points to a `Sized` type (a mutable reference). Therefore, we can convert this thin pointer into a `usize`, which