Skip to content

Commit a052945

Browse files
committed
add ?Sized bounds to traits in #[pin_data] macro
The `#[pin_data]` macro uses some auxiliary traits to ensure that a user does not implement `Drop` for the annotated struct, as that is unsound and can lead to UB. However, if the struct that is annotated is `!Sized`, the current bounds do not work, because `Sized` is an implicit bound for generics. This is *not* a soundness hole of pin-init, as it currently is impossible to construct an unsized struct using pin-init. Signed-off-by: Benno Lossin <[email protected]>
1 parent 651a5fd commit a052945

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

internal/src/pin_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn generate_drop_impl(
223223
// if it also implements `Drop`
224224
trait MustNotImplDrop {}
225225
#[expect(drop_bounds)]
226-
impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
226+
impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {}
227227
impl #impl_generics MustNotImplDrop for #ident #ty_generics
228228
#whr
229229
{}
@@ -232,7 +232,7 @@ fn generate_drop_impl(
232232
// `PinnedDrop` as the parameter to `#[pin_data]`.
233233
#[expect(non_camel_case_types)]
234234
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
235-
impl<T: ::pin_init::PinnedDrop>
235+
impl<T: ::pin_init::PinnedDrop + ?::core::marker::Sized>
236236
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
237237
impl #impl_generics
238238
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for #ident #ty_generics

tests/ui/expand/pin-data.expanded.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ const _: () = {
111111
{}
112112
trait MustNotImplDrop {}
113113
#[expect(drop_bounds)]
114-
impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
114+
impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {}
115115
impl MustNotImplDrop for Foo {}
116116
#[expect(non_camel_case_types)]
117117
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
118-
impl<T: ::pin_init::PinnedDrop> UselessPinnedDropImpl_you_need_to_specify_PinnedDrop
119-
for T {}
118+
impl<
119+
T: ::pin_init::PinnedDrop + ?::core::marker::Sized,
120+
> UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
120121
impl UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for Foo {}
121122
};

0 commit comments

Comments
 (0)