@@ -251,21 +251,20 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
251
251
//
252
252
// We go through a transition where:
253
253
//
254
- // * First, we set the data to be the closure that we're going to call.
254
+ // * First, we set the data field `f` to be the argumentless closure that we're going to call.
255
255
// * When we make the function call, the `do_call` function below, we take
256
- // ownership of the function pointer. At this point the `Data ` union is
256
+ // ownership of the function pointer. At this point the `data ` union is
257
257
// entirely uninitialized.
258
258
// * If the closure successfully returns, we write the return value into the
259
- // data's return slot. Note that `ptr::write` is used as it's overwriting
260
- // uninitialized data .
259
+ // data's return slot (field `r`).
260
+ // * If the closure panics (`do_catch` below), we write the panic payload into field `p` .
261
261
// * Finally, when we come back out of the `try` intrinsic we're
262
262
// in one of two states:
263
263
//
264
264
// 1. The closure didn't panic, in which case the return value was
265
- // filled in. We move it out of `data` and return it.
266
- // 2. The closure panicked, in which case the return value wasn't
267
- // filled in. In this case the entire `data` union is invalid, so
268
- // there is no need to drop anything.
265
+ // filled in. We move it out of `data.r` and return it.
266
+ // 2. The closure panicked, in which case the panic payload was
267
+ // filled in. We move it out of `data.p` and return it.
269
268
//
270
269
// Once we stack all that together we should have the "most efficient'
271
270
// method of calling a catch panic whilst juggling ownership.
0 commit comments