mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-21 14:22:26 +00:00
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:
parent
7311e9b4b8
commit
c9e1ae1373
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user