diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 6a40e8c..e16d43e 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -339,6 +339,12 @@ fn derive_marker_trait_inner( quote!() }; + let where_clause = if Trait::requires_where_clause() { + where_clause + } else { + None + }; + Ok(quote! { #asserts diff --git a/derive/src/traits.rs b/derive/src/traits.rs index 2e3fec9..2590267 100644 --- a/derive/src/traits.rs +++ b/derive/src/traits.rs @@ -32,6 +32,9 @@ pub trait Derivable { fn trait_impl(_input: &DeriveInput) -> Result<(TokenStream, TokenStream)> { Ok((quote!(), quote!())) } + fn requires_where_clause() -> bool { + true + } } pub struct Pod; @@ -300,6 +303,10 @@ impl Derivable for TransparentWrapper { } } } + + fn requires_where_clause() -> bool { + false + } } pub struct Contiguous; diff --git a/tests/derive.rs b/tests/derive.rs index 7859865..f06ff77 100644 --- a/tests/derive.rs +++ b/tests/derive.rs @@ -23,3 +23,29 @@ struct TransparentWithZeroSized { a: u16, b: (), } + +#[derive(TransparentWrapper)] +#[repr(transparent)] +struct TransparentWithGeneric { + a: T, +} + +/// Ensuring that no additional bounds are emitted. +/// See https://github.com/Lokathor/bytemuck/issues/145 +fn test_generic(x: T) -> TransparentWithGeneric { + TransparentWithGeneric::wrap(x) +} + +#[derive(TransparentWrapper)] +#[repr(transparent)] +#[transparent(T)] +struct TransparentWithGenericAndZeroSized { + a: T, + b: () +} + +/// Ensuring that no additional bounds are emitted. +/// See https://github.com/Lokathor/bytemuck/issues/145 +fn test_generic_with_zst(x: T) -> TransparentWithGenericAndZeroSized { + TransparentWithGenericAndZeroSized::wrap(x) +}