Skip to content

Commit dae5466

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. Tested-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Benno Lossin <lossin@kernel.org>
1 parent 560f6d1 commit dae5466

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
@@ -215,7 +215,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
215215
// if it also implements `Drop`
216216
trait MustNotImplDrop {}
217217
#[expect(drop_bounds)]
218-
impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
218+
impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {}
219219
impl #impl_generics MustNotImplDrop for #ident #ty_generics
220220
#whr
221221
{}
@@ -224,7 +224,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
224224
// `PinnedDrop` as the parameter to `#[pin_data]`.
225225
#[expect(non_camel_case_types)]
226226
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
227-
impl<T: ::pin_init::PinnedDrop>
227+
impl<T: ::pin_init::PinnedDrop + ?::core::marker::Sized>
228228
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
229229
impl #impl_generics
230230
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for #ident #ty_generics

0 commit comments

Comments
 (0)