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