Skip to content

Commit

Permalink
fix(schema): don't add Clone bound to the impl HasSchema when `no…
Browse files Browse the repository at this point in the history
…_clone`
  • Loading branch information
nelson137 committed Nov 23, 2024
1 parent df3e274 commit 6c838c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions framework_crates/bones_schema/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 = &param.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) = &param.bound {
impl_bounds.append(Punct::new('+', Spacing::Alone));
impl_bounds.extend(bound.tokens.iter().cloned());
Expand Down
17 changes: 17 additions & 0 deletions framework_crates/bones_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: HasSchema + Default>(T);

#[derive(HasSchema, Default)]
#[schema(no_clone)]
#[schema_module(crate)]
#[repr(C)]
struct NotClonable;

_ = Meta::<NotClonable>::schema();
}
}
}

0 comments on commit 6c838c7

Please sign in to comment.