Skip to content

Commit 0719659

Browse files
committed
revert supporting generics for deriving TypeUuid (#2204)
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))
1 parent 3cf10e2 commit 0719659

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate proc_macro;
22

3-
use quote::quote;
3+
use quote::{quote, ToTokens};
44
use syn::{parse::*, *};
55
use uuid::Uuid;
66

@@ -15,7 +15,11 @@ pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
1515

1616
// Build the trait implementation
1717
let name = &ast.ident;
18-
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
18+
19+
let (impl_generics, type_generics, _) = &ast.generics.split_for_impl();
20+
if !impl_generics.to_token_stream().is_empty() || !type_generics.to_token_stream().is_empty() {
21+
panic!("#[derive(TypeUuid)] is not supported for generics.");
22+
}
1923

2024
let mut uuid = None;
2125
for attribute in ast.attrs.iter().filter_map(|attr| attr.parse_meta().ok()) {
@@ -54,7 +58,7 @@ pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
5458
.map(|byte_str| syn::parse_str::<LitInt>(&byte_str).unwrap());
5559

5660
let gen = quote! {
57-
impl #impl_generics #bevy_reflect_path::TypeUuid for #name #type_generics #where_clause {
61+
impl #bevy_reflect_path::TypeUuid for #name {
5862
const TYPE_UUID: #bevy_reflect_path::Uuid = #bevy_reflect_path::Uuid::from_bytes([
5963
#( #bytes ),*
6064
]);

crates/bevy_reflect/src/type_uuid.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,3 @@ where
2222
std::any::type_name::<Self>()
2323
}
2424
}
25-
26-
#[cfg(test)]
27-
mod test {
28-
use super::*;
29-
30-
#[derive(TypeUuid)]
31-
#[uuid = "af6466c2-a9f4-11eb-bcbc-0242ac130002"]
32-
struct TestDeriveStruct<T>
33-
where
34-
T: Clone,
35-
{
36-
_value: T,
37-
}
38-
39-
fn test_impl_type_uuid(_: &impl TypeUuid) {}
40-
41-
#[test]
42-
fn test_generic_type_uuid_derive() {
43-
let test_struct = TestDeriveStruct { _value: 42 };
44-
test_impl_type_uuid(&test_struct);
45-
}
46-
}

0 commit comments

Comments
 (0)