-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Unalign
for unsized types?
#209
Comments
cc @djkoloski since you mentioned this behavior in #126 (comment) |
Requiring |
Ah hmmm yes that's a very good point. |
Okay, updated to describe our options. Seems like wrapping in a |
Since
Unalign<T>
isrepr(packed)
,T
must beSized
(you can switch toT: ?Sized + Copy
, but actually this is stillSized
becauseCopy: Clone
andClone: Sized
). We could lift this restriction by wrapping the innerT
in aManuallyDrop
. However, we'd need to figure out what to do about dropping. We could implementDrop
whenT: Sized
or whenT: Unaligned
(so dropping in-place is valid), but whenT: !Sized
, we'd either have to leak the type or else implement some crazy approximation of dynamic stack allocation in order to move the value into an aligned location in order to drop it in-place. Alternatively, perhaps we can prove that it's never possible to create an owned, unsizedUnalign<T>
, and so the no-drop thing never matters in practice?Background: If a type is
repr(packed)
, its fields may live at invalid offsets at runtime, which means that Rust must prevent those fields from being operated on in-place. If a field requires dropping, Rust generates drop glue for these fields by first moving them into the local stack frame with correct alignment. At this point, they can be safely dropped in-place. However, if the type is unsized, then there's no way for it to be moved into the local stack frame. Thus, Rust only allows unaligned fields which don't have drop glue. In the case of generic types, this requires wrapping in aManuallyDrop
.The text was updated successfully, but these errors were encountered: