mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Unconditionally derive ToComputedValue as Clone for non-generics
We assume that types such as `<Self as ToComputedValue>::ToComputedValue == Self` just construct a new value that is just a clone of the original one without any additional code.
This commit is contained in:
parent
0eb8b1f4c0
commit
b517bcd42b
2 changed files with 27 additions and 1 deletions
|
@ -13,6 +13,29 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
let (impl_generics, ty_generics, mut where_clause, computed_value_type) =
|
||||
cg::fmap_trait_parts(&input, &trait_path, Ident::from("ComputedValue"));
|
||||
|
||||
if input.generics.params.is_empty() {
|
||||
return quote! {
|
||||
impl #impl_generics ::values::computed::ToComputedValue for #name #ty_generics
|
||||
#where_clause
|
||||
{
|
||||
type ComputedValue = #computed_value_type;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(
|
||||
&self,
|
||||
_context: &::values::computed::Context,
|
||||
) -> Self::ComputedValue {
|
||||
::std::clone::Clone::clone(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
::std::clone::Clone::clone(computed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let to_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
||||
let attrs = cg::parse_field_attrs::<ComputedValueAttrs>(&binding.ast());
|
||||
if attrs.clone {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue