@@ -342,11 +342,12 @@ impl<T, const N: usize> Sender<'_, T, N> {
342
342
// We are already in the wait queue.
343
343
if let Some ( link) = link {
344
344
if link. is_popped ( ) {
345
+ // SAFETY: `free_slot_ptr` is valid for writes until the end of this future.
346
+ let slot = unsafe { free_slot_ptr. replace ( None , cs) } ;
347
+
345
348
// If our link is popped, then:
346
349
// 1. We were popped by `try_recv` and it provided us with a slot.
347
350
// 2. We were popped by `Receiver::drop` and it did not provide us with a slot, and the channel is closed.
348
- let slot = unsafe { free_slot_ptr. replace ( None , cs) } ;
349
-
350
351
if let Some ( slot) = slot {
351
352
Poll :: Ready ( Ok ( slot) )
352
353
} else {
@@ -365,10 +366,10 @@ impl<T, const N: usize> Sender<'_, T, N> {
365
366
366
367
// SAFETY(new_unchecked): The address to the link is stable as it is defined
367
368
// outside this stack frame.
368
- // SAFETY(push): `link_ref` lifetime comes from `link_ptr` that is shadowed,
369
- // and we make sure in `dropper` that the link is removed from the queue
369
+ // SAFETY(push): `link_ref` lifetime comes from `link_ptr` and `free_slot_ptr` that
370
+ // are shadowed and we make sure in `dropper` that the link is removed from the queue
370
371
// before dropping `link_ptr` AND `dropper` makes sure that the shadowed
371
- // `link_ptr` lives until the end of the stack frame.
372
+ // `ptr`s live until the end of the stack frame.
372
373
unsafe { self . 0 . wait_queue . push ( Pin :: new_unchecked ( link_ref) ) } ;
373
374
374
375
Poll :: Pending
0 commit comments