Skip to content

Commit 07ec548

Browse files
committed
rust: pin-init: 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 <lossin@kernel.org>
1 parent b948896 commit 07ec548

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

rust/pin-init/internal/src/pin_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
228228
// if it also implements `Drop`
229229
trait MustNotImplDrop {}
230230
#[expect(drop_bounds)]
231-
impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
231+
impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {}
232232
impl #impl_generics MustNotImplDrop for #ident #ty_generics
233233
#whr
234234
{}
@@ -237,7 +237,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
237237
// `PinnedDrop` as the parameter to `#[pin_data]`.
238238
#[expect(non_camel_case_types)]
239239
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
240-
impl<T: ::pin_init::PinnedDrop>
240+
impl<T: ::pin_init::PinnedDrop + ?::core::marker::Sized>
241241
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
242242
impl #impl_generics
243243
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for #ident #ty_generics

0 commit comments

Comments
 (0)