@@ -518,7 +518,11 @@ macro_rules! __pinned_drop {
518518 }
519519 ) ,
520520 ) => {
521- // SAFETY: TODO.
521+ // SAFETY: This macro generates the `unsafe impl PinnedDrop`. This is safe as it's
522+ // an internal part of the `#[pinned_drop]` proc-macro, which ensures correct
523+ // transformation of the user's `impl`. The added `OnlyCallFromDrop` token restricts
524+ // `PinnedDrop::drop` calls to the actual drop process (via the `Drop::drop` impl
525+ // generated by `#[pin_data(PinnedDrop)]`) where `self` is pinned and valid.
522526 unsafe $( $impl_sig) * {
523527 // Inherit all attributes and the type/ident tokens for the signature.
524528 $( #[ $( $attr) * ] ) *
@@ -878,7 +882,12 @@ macro_rules! __pin_data {
878882 }
879883 }
880884
881- // SAFETY: TODO.
885+ // SAFETY: The `__pin_data` macro ensures this `impl PinData` for `__ThePinData` is
886+ // safe by guaranteeing that `__ThePinData` is `Copy`, `PinData::Datee` is correctly
887+ // set to `$name` (which itself implements `HasPinData<PinData = __ThePinData>`), and
888+ // that all generated field accessor methods on `__ThePinData` are sound, uphold their
889+ // individual safety contracts (such as ensuring valid `slot` pointers), and correctly
890+ // use either `$crate::PinInit::__pinned_init` or `$crate::Init::__init`.
882891 unsafe impl <$( $impl_generics) * >
883892 $crate:: __internal:: PinData for __ThePinData<$( $ty_generics) * >
884893 where $( $whr) *
@@ -1000,23 +1009,34 @@ macro_rules! __pin_data {
10001009 {
10011010 $(
10021011 $( #[ $( $p_attr) * ] ) *
1012+ /// # Safety
1013+ ///
1014+ /// The caller must ensure that `slot` is a valid pointer to uninitialized memory
1015+ /// that is properly aligned and large enough to hold a value of type `$p_type`.
1016+ /// `slot` is a pointer valid for writes and any value written to it is pinned.
10031017 $pvis unsafe fn $p_field<E >(
10041018 self ,
10051019 slot: * mut $p_type,
10061020 init: impl $crate:: PinInit <$p_type, E >,
10071021 ) -> :: core:: result:: Result <( ) , E > {
1008- // SAFETY: TODO .
1022+ // SAFETY: `slot` points to valid, uninitialized memory for a `$p_type` .
10091023 unsafe { $crate:: PinInit :: __pinned_init( init, slot) }
10101024 }
10111025 ) *
10121026 $(
10131027 $( #[ $( $attr) * ] ) *
1028+ /// # Safety
1029+ ///
1030+ /// The caller must ensure that `slot` is a valid pointer to uninitialized memory
1031+ /// that is properly aligned and large enough to hold a value of type `$type`.
1032+ /// The memory at `slot` must also be valid for writes.
1033+ /// `slot` is valid for writes.
10141034 $fvis unsafe fn $field<E >(
10151035 self ,
10161036 slot: * mut $type,
10171037 init: impl $crate:: Init <$type, E >,
10181038 ) -> :: core:: result:: Result <( ) , E > {
1019- // SAFETY: TODO .
1039+ // SAFETY: `slot` points to valid, uninitialized memory for a `$type` .
10201040 unsafe { $crate:: Init :: __init( init, slot) }
10211041 }
10221042 ) *
@@ -1132,7 +1152,11 @@ macro_rules! __init_internal {
11321152 struct __InitOk;
11331153 // Get the data about fields from the supplied type.
11341154 //
1135- // SAFETY: TODO.
1155+ // SAFETY: The `$get_data()` call (which resolves to either `HasPinData::__pin_data()`
1156+ // or `HasInitData::__init_data()`) is safe because this macro is part of the pin-init
1157+ // crate, satisfying the safety requirement that these methods should only be called by
1158+ // macros in the pin-init crate (as documented in their respective `# Safety` sections).
1159+ // The `paste!` macro is used for re-tokenization and does not affect this safety argument.
11361160 let data = unsafe {
11371161 use $crate:: __internal:: $has_data;
11381162 // Here we abuse `paste!` to retokenize `$t`. Declarative macros have some internal
@@ -1188,7 +1212,12 @@ macro_rules! __init_internal {
11881212 let init = move |slot| -> :: core:: result:: Result <( ) , $err> {
11891213 init( slot) . map( |__InitOk| ( ) )
11901214 } ;
1191- // SAFETY: TODO.
1215+ // SAFETY: The `init` closure, generated by this macro, upholds the contract of
1216+ // `$crate::$construct_closure`. It ensures `slot` is fully initialized on `Ok(())`
1217+ // or properly cleaned (via `DropGuard`s) on `Err(err)`, leaving `slot` safe to
1218+ // deallocate. Pinning invariants are maintained using `PinData`/`InitData` methods
1219+ // for field initialization, and `slot` is not moved (for `!Unpin` types) as it's
1220+ // accessed via a pointer.
11921221 let init = unsafe { $crate:: $construct_closure:: <_, $err>( init) } ;
11931222 init
11941223 } } ;
@@ -1338,7 +1367,8 @@ macro_rules! __init_internal {
13381367 // Since we are in the closure that is never called, this will never get executed.
13391368 // We abuse `slot` to get the correct type inference here:
13401369 //
1341- // SAFETY: TODO.
1370+ // SAFETY: This is unreachable code that is used solely for compile-time type checking,
1371+ // it is never executed.
13421372 unsafe {
13431373 // Here we abuse `paste!` to retokenize `$t`. Declarative macros have some internal
13441374 // information that is associated to already parsed fragments, so a path fragment
0 commit comments