@@ -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,32 @@ 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`.
10031016 $pvis unsafe fn $p_field<E >(
10041017 self ,
10051018 slot: * mut $p_type,
10061019 init: impl $crate:: PinInit <$p_type, E >,
10071020 ) -> :: core:: result:: Result <( ) , E > {
1008- // SAFETY: TODO .
1021+ // SAFETY: `slot` points to valid, uninitialized memory for a `$p_type` .
10091022 unsafe { $crate:: PinInit :: __pinned_init( init, slot) }
10101023 }
10111024 ) *
10121025 $(
10131026 $( #[ $( $attr) * ] ) *
1027+ /// # Safety
1028+ ///
1029+ /// The caller must ensure that `slot` is a valid pointer to uninitialized memory
1030+ /// that is properly aligned and large enough to hold a value of type `$type`.
1031+ /// The memory at `slot` must also be valid for writes.
10141032 $fvis unsafe fn $field<E >(
10151033 self ,
10161034 slot: * mut $type,
10171035 init: impl $crate:: Init <$type, E >,
10181036 ) -> :: core:: result:: Result <( ) , E > {
1019- // SAFETY: TODO .
1037+ // SAFETY: `slot` points to valid, uninitialized memory for a `$type` .
10201038 unsafe { $crate:: Init :: __init( init, slot) }
10211039 }
10221040 ) *
@@ -1132,7 +1150,12 @@ macro_rules! __init_internal {
11321150 struct __InitOk;
11331151 // Get the data about fields from the supplied type.
11341152 //
1135- // SAFETY: TODO.
1153+ // SAFETY: The `$get_data()` call (which resolves to either `HasPinData::__pin_data()`
1154+ // or `HasInitData::__init_data()`) is safe because the `#[pin_data]` macro, when applied
1155+ // to type `$t`, correctly implements the respective trait. This ensures that the returned
1156+ // metadata accurately reflects `$t`'s structure and pinning properties, fulfilling the
1157+ // `# Safety` contract of the called `__pin_data()` or `__init_data()` method.
1158+ // The `paste!` macro is used for re-tokenization and does not affect this safety argument.
11361159 let data = unsafe {
11371160 use $crate:: __internal:: $has_data;
11381161 // Here we abuse `paste!` to retokenize `$t`. Declarative macros have some internal
@@ -1188,7 +1211,12 @@ macro_rules! __init_internal {
11881211 let init = move |slot| -> :: core:: result:: Result <( ) , $err> {
11891212 init( slot) . map( |__InitOk| ( ) )
11901213 } ;
1191- // SAFETY: TODO.
1214+ // SAFETY: The `init` closure, generated by this macro, upholds the contract of
1215+ // `$crate::$construct_closure`. It ensures `slot` is fully initialized on `Ok(())`
1216+ // or properly cleaned (via `DropGuard`s) on `Err(err)`, leaving `slot` safe to
1217+ // deallocate. Pinning invariants are maintained using `PinData`/`InitData` methods
1218+ // for field initialization, and `slot` is not moved (for `!Unpin` types) as it's
1219+ // accessed via a pointer.
11921220 let init = unsafe { $crate:: $construct_closure:: <_, $err>( init) } ;
11931221 init
11941222 } } ;
@@ -1338,7 +1366,8 @@ macro_rules! __init_internal {
13381366 // Since we are in the closure that is never called, this will never get executed.
13391367 // We abuse `slot` to get the correct type inference here:
13401368 //
1341- // SAFETY: TODO.
1369+ // SAFETY: This is unreachable code that is used solely for compile-time type checking,
1370+ // it is never executed.
13421371 unsafe {
13431372 // Here we abuse `paste!` to retokenize `$t`. Declarative macros have some internal
13441373 // information that is associated to already parsed fragments, so a path fragment
0 commit comments