-
Notifications
You must be signed in to change notification settings - Fork 106
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 derive(KnownLayout)
on DSTs
#643
Conversation
2557457
to
dcc339b
Compare
b500286
to
8d0ddf7
Compare
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.
Need to add tests, notably:
- In
src/lib.rs
, the impl tests for types likeUnalign
should test with both sized and unsized types - UI failure tests for the following cases:
- Type is
repr(C)
, trailing field is a concrete type (not a type parameter), and trailing field doesn't implementKnownLayout
- Type is not
repr(C)
, trailing field is a concrete type (not a type parameter), and trailing field is unsized
- Type is
- Non-UI tests for all combinations of the following axes:
-
repr(C)
/notrepr(C)
- Trailing field is concrete/generic
- Trailing field does/does not implement
KnownLayout
- Trailing field is sized/unsized
-
5345efa
to
af44c49
Compare
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.
For success cases, can we also test that we get the expected value for KnownLayout::LAYOUT
?
It's probably also worth adding a test along these lines:
#[repr(C)]
struct Foo<A, B, C>(A, B, C);
macro_rules! test_foo {
($a:ty, $b:ty, $c:ty => $layout:expr) => {
assert_eq!(<Foo<$a, $b, $c> as KnownLayout>::LAYOUT, $layout);
};
}
// TODO: A bunch of different combinations of types with different sizes and alignments
233aa78
to
786a279
Compare
struct NotKnownLayout<T = ()> { | ||
_t: T, | ||
} |
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.
Does this need a repr?
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.
Discussed offline: It could use a repr(transparent)
, but it would be sufficiently interesting if this test started failing on a future Rust version, that it'd be nice to get the heads up.
ab87b85
to
8b28748
Compare
DSTs must be marked with `repr(C)`. The expansion requires the final field implement `KnownLayout`. Makes progress towards #29.
8b28748
to
fb70716
Compare
Makes progress towards #29. Supersedes #541.
For types marked
#[repr(C)]
, this derive requires that the trailing field isKnownLayout
:For non-
repr(C)
layouts, it's only required thatSelf: Sized
.