Skip to content

Commit

Permalink
fix: generate better code.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Aug 7, 2024
1 parent 2db4f9c commit e8ec71e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tasks/ast_codegen/src/generators/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,30 @@ where
F: FnOnce() -> (/* allocator name */ Ident, TokenStream),
{
let (alloc, body) = body();
let (old_lifetime, new_lifetime) = if has_lifetime {
(quote!(<'old_alloc>), quote!(<'new_alloc>))
let (impl_lifetimes, trait_lifetime, old_lifetime, new_lifetime, alloc_ref) = if has_lifetime {
(
quote!(<'old_alloc, 'new_alloc>),
quote!(<'new_alloc>),
quote!(<'old_alloc>),
quote!(<'new_alloc>),
quote!(&'new_alloc),
)
} else {
Default::default()
(
quote!(<'alloc>),
quote!(<'alloc>),
TokenStream::default(),
TokenStream::default(),
quote!(&'alloc),
)
};

quote! {
endl!();
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for #ty_ident #old_lifetime {
impl #impl_lifetimes CloneIn #trait_lifetime for #ty_ident #old_lifetime {
type Cloned = #ty_ident #new_lifetime;

fn clone_in(&self, #alloc: &'new_alloc Allocator) -> Self::Cloned {
fn clone_in(&self, #alloc: #alloc_ref Allocator) -> Self::Cloned {
#body
}
}
Expand Down

0 comments on commit e8ec71e

Please sign in to comment.