Remove where clause from derived TransparentWrapper impls. (#146)

* Remove where clause from derived TransparentWrapper impls.

* Add test for TransparentWrapper trait bound regression.
This commit is contained in:
zachs18 2022-11-20 17:40:20 -06:00 committed by GitHub
parent 7311e9b4b8
commit c9e1ae1373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -339,6 +339,12 @@ fn derive_marker_trait_inner<Trait: Derivable>(
quote!()
};
let where_clause = if Trait::requires_where_clause() {
where_clause
} else {
None
};
Ok(quote! {
#asserts

View File

@ -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;

View File

@ -23,3 +23,29 @@ struct TransparentWithZeroSized {
a: u16,
b: (),
}
#[derive(TransparentWrapper)]
#[repr(transparent)]
struct TransparentWithGeneric<T> {
a: T,
}
/// Ensuring that no additional bounds are emitted.
/// See https://github.com/Lokathor/bytemuck/issues/145
fn test_generic<T>(x: T) -> TransparentWithGeneric<T> {
TransparentWithGeneric::wrap(x)
}
#[derive(TransparentWrapper)]
#[repr(transparent)]
#[transparent(T)]
struct TransparentWithGenericAndZeroSized<T> {
a: T,
b: ()
}
/// Ensuring that no additional bounds are emitted.
/// See https://github.com/Lokathor/bytemuck/issues/145
fn test_generic_with_zst<T>(x: T) -> TransparentWithGenericAndZeroSized<T> {
TransparentWithGenericAndZeroSized::wrap(x)
}