-
Notifications
You must be signed in to change notification settings - Fork 104
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
Initial commit of DstLayout::for_dst #541
Conversation
824e41f
to
85ed994
Compare
d0fcb15
to
21cea7e
Compare
5927d5b
to
8956931
Compare
// SAFETY: TODO | ||
SizeInfo::Sized { _size } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is sound for non-repr(C)
types. Rust reserves the right to add excess padding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah very good point. Maybe rename to for_repr_c_dst
or something? And add a safety precondition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should the UX of the derive be? Some possibilities:
- unconditionally require
repr(C)
on structs. - don't unconditionally require
repr(C)
, but expand toDstLayout::for_type::<Self>()
on non-repr(C)
types, andDstLayout::for_repr_c_dst
onrepr(C)
types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I'd prefer the latter, but how can we make the UX of the error message good when the user tries to derive on an unsized, non-repr(C)
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but not sure yet how good the UX can be. This still needs UI tests.
05fd194
to
da522c6
Compare
src/lib.rs
Outdated
@@ -3908,6 +3965,80 @@ mod tests { | |||
} | |||
} | |||
|
|||
mod for_dst { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thinking behind having these in a nested module as opposed to just naming them test_dst_layout_for_sized
etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- reduces repetition in the names
- makes it possible to code-collapse the entire group in an editor
My preference (not in this PR) would be even to go a little further and drop test_
from all tests. All of the tests are already located in a module called "tests".
panic!(concat!( | ||
"cannot compute layout of `", | ||
stringify!($ty), | ||
"`; type is larger than zerocopy supports" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a TODO so we don't forget: We should have an issue link here so there's a way for users to report that they need support for larger types.
ef0f250
to
4a2c8f0
Compare
This will be used by the custom derive of `KnownLayout` to compute the `DstLayout` for unsized types. Makes progress on #29 Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
4a2c8f0
to
558ca65
Compare
This will be used by the custom derive of
KnownLayout
to compute theDstLayout
for unsized types.Makes progress on #29