Skip to content

test(model): bitflags static assertions + serde#2088

Merged
spring4175 merged 2 commits intomainfrom
zeyla/test-model-bitflags
Jan 28, 2023
Merged

test(model): bitflags static assertions + serde#2088
spring4175 merged 2 commits intomainfrom
zeyla/test-model-bitflags

Conversation

@spring4175
Copy link
Contributor

Add static assertions for bitflag implementations and constant values, as well as tests for the serde implementations. The serde tests include a test for the (de)serialization of a variant and that unknown bits are truncated on deserialization.

Add static assertions for bitflag implementations and constant values,
as well as tests for the serde implementations. The serde tests include
a test for the (de)serialization of a variant and that unknown bits are
truncated on deserialization.
@github-actions github-actions bot added c-model Affects the model crate t-test PR *only* affecting tests. labels Jan 25, 2023
spring4175 added a commit that referenced this pull request Jan 25, 2023
Bitflags received from the Discord API are truncated when deserialized.
However, we have recently taken a model of accepting "unknown
information", with our recent reworks of enums the shining example.
Instead of failing to deserialize / ignore "unknown variants" we have
taken the step to treat unknown data as "first class", in that Twilight
not necessarily registering known values is okay and users can manually
handle variants as they need. We should apply the same logic to bitflags
and not trim unknown data.

This unfortunately makes use of unsafe code for constructing bitflags in
tests, because `bitflags` has an unorthodox definition of what "unsafe"
is for its `Bitflags::from_bits_unchecked` function. `bitflags` treats
unknown bits as being "unsafe", and so the function to construct
bitflags with possibly unknown variants is unsafe. I have added notes
detailing this.

This is a breaking change because unknown bits are no longer truncated.

Blocks on PR #2088.
Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a rare case where I think we could make this better by using a macro to construct the assert_impl_all, to ensure that all are updated if we do it one place, but I think that is outside the general scope of this pr and can be done later

@spring4175 spring4175 merged commit 3d6146e into main Jan 28, 2023
@spring4175 spring4175 deleted the zeyla/test-model-bitflags branch January 28, 2023 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-model Affects the model crate t-test PR *only* affecting tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments