Skip to content
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] - revert supporting generics for deriving TypeUuid #2204

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate proc_macro;

use quote::quote;
use quote::{quote, ToTokens};
use syn::{parse::*, *};
use uuid::Uuid;

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

// Build the trait implementation
let name = &ast.ident;
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();

let (impl_generics, type_generics, _) = &ast.generics.split_for_impl();
if !impl_generics.to_token_stream().is_empty() || !type_generics.to_token_stream().is_empty() {
panic!("#[derive(TypeUuid)] is not supported for generics.");
}

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

let gen = quote! {
impl #impl_generics #bevy_reflect_path::TypeUuid for #name #type_generics #where_clause {
impl #bevy_reflect_path::TypeUuid for #name {
const TYPE_UUID: #bevy_reflect_path::Uuid = #bevy_reflect_path::Uuid::from_bytes([
#( #bytes ),*
]);
Expand Down
22 changes: 0 additions & 22 deletions crates/bevy_reflect/src/type_uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,3 @@ where
std::any::type_name::<Self>()
}
}

#[cfg(test)]
mod test {
use super::*;

#[derive(TypeUuid)]
#[uuid = "af6466c2-a9f4-11eb-bcbc-0242ac130002"]
struct TestDeriveStruct<T>
where
T: Clone,
{
_value: T,
}

fn test_impl_type_uuid(_: &impl TypeUuid) {}

#[test]
fn test_generic_type_uuid_derive() {
let test_struct = TestDeriveStruct { _value: 42 };
test_impl_type_uuid(&test_struct);
}
}