diff --git a/framework_crates/bones_schema/macros/src/lib.rs b/framework_crates/bones_schema/macros/src/lib.rs index 0929a32ebe..efda2c13d5 100644 --- a/framework_crates/bones_schema/macros/src/lib.rs +++ b/framework_crates/bones_schema/macros/src/lib.rs @@ -1,5 +1,5 @@ use proc_macro::TokenStream; -use proc_macro2::{Punct, Spacing, TokenStream as TokenStream2, TokenTree as TokenTree2}; +use proc_macro2::{Ident, Punct, Spacing, TokenStream as TokenStream2, TokenTree as TokenTree2}; use quote::{format_ident, quote, quote_spanned, spanned::Spanned, TokenStreamExt}; use venial::StructFields; @@ -376,7 +376,11 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream { let mut impl_bounds = TokenStream2::new(); for (param, comma) in generic_params.params.iter() { let name = ¶m.name; - impl_bounds.extend(quote!(#name : HasSchema + Clone)); + impl_bounds.extend(quote!(#name : HasSchema)); + if !no_clone { + impl_bounds.append(Punct::new('+', Spacing::Alone)); + impl_bounds.append(Ident::new("Clone", input.__span())); + } if let Some(bound) = ¶m.bound { impl_bounds.append(Punct::new('+', Spacing::Alone)); impl_bounds.extend(bound.tokens.iter().cloned()); diff --git a/framework_crates/bones_schema/src/lib.rs b/framework_crates/bones_schema/src/lib.rs index 887587543b..4a8eef3a75 100644 --- a/framework_crates/bones_schema/src/lib.rs +++ b/framework_crates/bones_schema/src/lib.rs @@ -168,5 +168,22 @@ mod test { assert_eq!(A::schema().layout(), B::schema().layout()); assert_eq!(C::schema().layout(), D::schema().layout()); } + + #[test] + fn generic_no_clone() { + #[derive(HasSchema, Default)] + #[schema(no_clone)] + #[schema_module(crate)] + #[repr(C)] + struct Meta(T); + + #[derive(HasSchema, Default)] + #[schema(no_clone)] + #[schema_module(crate)] + #[repr(C)] + struct NotClonable; + + _ = Meta::::schema(); + } } }