-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Bevy derives handling generics in impl definitions. #2044
[Merged by Bors] - Bevy derives handling generics in impl definitions. #2044
Conversation
A few comments to take into account!
|
f534f8d
to
778d00f
Compare
Could you edit the PR description to change |
I would like to see this; I think it's a sensible place to put them. |
I dig it! I personally think the tests should live in the crates where the macros are actually consumed/exported (ex:
|
778d00f
to
b80fc26
Compare
Tests are added for |
bors r+ |
Fixes #2037 (and then some) Problem: - `TypeUuid`, `RenderResource`, and `Bytes` derive macros did not properly handle generic structs. Solution: - Rework the derive macro implementations to handle the generics.
Pull request successfully merged into main. Build succeeded: |
I might be missing something here, but doesn't this mean that different instantiations of a generic type deriving I'd love tools for making generics and reflection work better together, of course. Maybe add a generic bound to the impl that the child is |
Hmm yeah supporting generics on TypeUuid derives does seem wrong. I think we should revert that change. |
This reverts some of the changes made in #2044 as supporting generics for a `#[derive(TypeUuid)]` should not work as each generic instantiation would have the same uuid. Stems from [this conversation](#2044 (comment))
@SafariMonkey this was fixed in #2204, that you for finding this bug! |
Fixes bevyengine#2037 (and then some) Problem: - `TypeUuid`, `RenderResource`, and `Bytes` derive macros did not properly handle generic structs. Solution: - Rework the derive macro implementations to handle the generics.
This reverts some of the changes made in bevyengine#2044 as supporting generics for a `#[derive(TypeUuid)]` should not work as each generic instantiation would have the same uuid. Stems from [this conversation](bevyengine#2044 (comment))
Support for deriving `TypeUuid` for types with generics was initially added in #2044 but later reverted #2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
Support for deriving `TypeUuid` for types with generics was initially added in bevyengine#2044 but later reverted bevyengine#2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
Support for deriving `TypeUuid` for types with generics was initially added in bevyengine#2044 but later reverted bevyengine#2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
Fixes #2037 (and then some)
Problem:
TypeUuid
,RenderResource
, andBytes
derive macros did not properly handle generic structs.Solution: