-
Notifications
You must be signed in to change notification settings - Fork 15
Fix struct_extensions projections on mapped and container types #48
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
Conversation
020c952 to
bc0c8f8
Compare
| .write_c(test.c); | ||
| prop_assert!(builder.is_init()); | ||
| builder.finish(); | ||
| let init = unsafe { uninit.assume_init() }; |
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.
could use int_uninit_mut() here
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.
| fn test_struct_extensions_with_container() { | ||
| #[derive(SchemaWrite, SchemaRead, Debug, PartialEq, Eq, proptest_derive::Arbitrary)] | ||
| #[wincode(internal, struct_extensions)] | ||
| struct Test { |
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.
since there is a non-trivial SchemaRead lifetime handling, could you add a test that works on struct with lifetimes, say
struct TestRef<'a> {
a: &'a [u8],
b: Option<'a u8>
}it should be possible to initialize it with a (locally scoped) slice, right?
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.
Sure, 5ed3c6b
|
Interestingly, tests show UB now? |
Yeah, looks like miri didn't like |
struct_extensionscurrently usesfield.target_resolved()to determine member projection types. This is incorrect for cases where a struct member is annotated with acontainertype, astarget_resolvedwill return the fully inferred container type, rather than the underlying type.For example
target_resolved()returnscontainers::Pod<[u8; 32]>, whereas we actually want the[u8; 32]directly.The fix here is simple -- just use
<field.ty as SchemaRead>::Dstrather thanfield.target_resolved(). This works for mapped types, container types, and plain built-in types.Example mapped type
Added tests that will fail to compile on current
master.