Skip to content

Commit 2dde1c8

Browse files
tamirdojeda
authored andcommitted
rust: sync: document PhantomData in Arc
Add a comment explaining the relevant semantics of `PhantomData`. This should help future readers who may, as I did, assume that this field is redundant at first glance. Signed-off-by: Tamir Duberstein <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 3f4223c commit 2dde1c8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

rust/kernel/sync/arc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ mod std_vendor;
127127
/// ```
128128
pub struct Arc<T: ?Sized> {
129129
ptr: NonNull<ArcInner<T>>,
130+
// NB: this informs dropck that objects of type `ArcInner<T>` may be used in `<Arc<T> as
131+
// Drop>::drop`. Note that dropck already assumes that objects of type `T` may be used in
132+
// `<Arc<T> as Drop>::drop` and the distinction between `T` and `ArcInner<T>` is not presently
133+
// meaningful with respect to dropck - but this may change in the future so this is left here
134+
// out of an abundance of caution.
135+
//
136+
// See https://doc.rust-lang.org/nomicon/phantom-data.html#generic-parameters-and-drop-checking
137+
// for more detail on the semantics of dropck in the presence of `PhantomData`.
130138
_p: PhantomData<ArcInner<T>>,
131139
}
132140

0 commit comments

Comments
 (0)