Skip to content

Commit

Permalink
Merge pull request #66 from dewert99/method-lifetime-params
Browse files Browse the repository at this point in the history
Method lifetime params
  • Loading branch information
dewert99 authored Jul 18, 2024
2 parents 5e1d048 + 0e8bb76 commit 65948ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ambassador/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,18 @@ fn build_method_invocation(
})
.collect();

let generics = method_sig.generics.split_for_impl().1;
let turbofish = generics.as_turbofish();
let generics = method_sig.generics.params.iter().filter_map(|x| match x {
GenericParam::Type(t) => Some(&t.ident),
GenericParam::Lifetime(_) => None,
GenericParam::Const(c) => Some(&c.ident),
});
let post = if original_method.sig.asyncness.is_some() {
quote!(.await)
} else {
quote!()
};

let method_invocation = quote! { #field_ident.#method_ident #turbofish(#argument_list) #post };
let method_invocation =
quote! { #field_ident.#method_ident::<#(#generics,)*>(#argument_list) #post };
method_invocation
}
22 changes: 22 additions & 0 deletions ambassador/tests/run-pass/late_bound_lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![deny(late_bound_lifetime_arguments)]
extern crate ambassador;

use ambassador::{delegatable_trait, Delegate};

#[delegatable_trait]
pub trait Shout {
fn shout<'a>(&'a self) {
println!("SHOUT!")
}
}

pub struct A;
impl Shout for A {}

#[derive(Delegate)]
#[delegate(Shout, target = "0")]
pub struct B(A);

fn main() {
B(A).shout()
}

0 comments on commit 65948ef

Please sign in to comment.