@@ -180,9 +180,11 @@ impl PartialEq for RawWakerVTable {
180
180
#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
181
181
impl fmt:: Debug for RawWakerVTable {
182
182
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
183
+ // SAFETY: Matching on unions is always unsafe.
184
+ // The determinant of this union is that `v2`'s padding must always be null pointers, i.e. v1's adapter fields must be `Some(_)`
183
185
unsafe {
184
186
match self {
185
- RawWakerVTable { v1 } if v1. other_adapter . is_none ( ) => self . v1 . fmt ( f) ,
187
+ RawWakerVTable { v1 } if v1. other_adapter . is_some ( ) => self . v1 . fmt ( f) ,
186
188
RawWakerVTable { v2 } => v2. fmt ( f) ,
187
189
}
188
190
}
@@ -196,12 +198,14 @@ unsafe extern "C" fn clone_adapter(
196
198
clone : unsafe fn ( * const ( ) ) -> RawWaker ,
197
199
data : * const ( ) ,
198
200
) -> RawWaker {
201
+ // SAFETY: The safety constraints are passed up to the caller
199
202
unsafe { ( clone) ( data) }
200
203
}
201
204
#[ allow( improper_ctypes_definitions) ]
202
205
/// # Safety
203
206
/// This function must only be called with function pointers sourced from the same shared object
204
207
unsafe extern "C" fn other_adapter ( other : unsafe fn ( * const ( ) ) , data : * const ( ) ) {
208
+ // SAFETY: The safety constraints are passed up to the caller
205
209
unsafe { ( other) ( data) }
206
210
}
207
211
impl RawWakerVTable {
@@ -447,6 +451,8 @@ impl Waker {
447
451
// SAFETY: This is safe because `Waker::from_raw` is the only way
448
452
// to initialize `wake` and `data` requiring the user to acknowledge
449
453
// that the contract of `RawWaker` is upheld.
454
+ // Matching on unions is always unsafe.
455
+ // The determinant of this union is that `v2`'s padding must always be null pointers, i.e. v1's adapter fields must be `Some(_)`
450
456
unsafe {
451
457
match * vtable {
452
458
RawWakerVTable {
@@ -470,6 +476,8 @@ impl Waker {
470
476
let RawWaker { data, vtable } = self . waker ;
471
477
472
478
// SAFETY: see `wake`
479
+ // Matching on unions is always unsafe.
480
+ // The determinant of this union is that `v2`'s padding must always be null pointers, i.e. v1's adapter fields must be `Some(_)`
473
481
unsafe {
474
482
match * vtable {
475
483
RawWakerVTable {
@@ -525,6 +533,8 @@ impl Clone for Waker {
525
533
// SAFETY: This is safe because `Waker::from_raw` is the only way
526
534
// to initialize `clone` and `data` requiring the user to acknowledge
527
535
// that the contract of [`RawWaker`] is upheld.
536
+ // Matching on unions is always unsafe.
537
+ // The determinant of this union is that `v2`'s padding must always be null pointers, i.e. v1's adapter fields must be `Some(_)`
528
538
waker : unsafe {
529
539
match * vtable {
530
540
RawWakerVTable {
@@ -545,6 +555,8 @@ impl Drop for Waker {
545
555
// SAFETY: This is safe because `Waker::from_raw` is the only way
546
556
// to initialize `drop` and `data` requiring the user to acknowledge
547
557
// that the contract of `RawWaker` is upheld.
558
+ // Matching on unions is always unsafe.
559
+ // The determinant of this union is that `v2`'s padding must always be null pointers, i.e. v1's adapter fields must be `Some(_)`
548
560
unsafe {
549
561
match * vtable {
550
562
RawWakerVTable {
0 commit comments