From eb8e71330a9894233c6559104756176b9a77188c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 30 Nov 2023 18:25:01 +0400 Subject: [PATCH] fix: forward type parameters --- ambassador/src/register.rs | 5 ++- ambassador/tests/run-pass/generic_method.rs | 46 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ambassador/tests/run-pass/generic_method.rs diff --git a/ambassador/src/register.rs b/ambassador/src/register.rs index 37fe0e4..b8dd281 100644 --- a/ambassador/src/register.rs +++ b/ambassador/src/register.rs @@ -312,6 +312,9 @@ fn build_method_invocation( }) .collect(); - let method_invocation = quote! { #field_ident.#method_ident(#argument_list) }; + let generics = method_sig.generics.split_for_impl().1; + let turbofish = generics.as_turbofish(); + + let method_invocation = quote! { #field_ident.#method_ident #turbofish(#argument_list) }; method_invocation } diff --git a/ambassador/tests/run-pass/generic_method.rs b/ambassador/tests/run-pass/generic_method.rs new file mode 100644 index 0000000..4acea3e --- /dev/null +++ b/ambassador/tests/run-pass/generic_method.rs @@ -0,0 +1,46 @@ +extern crate ambassador; + +use ambassador::{delegatable_trait, Delegate}; + +trait StaticFn { + fn call() -> bool; +} + +struct StaticTrue; +struct StaticFalse; + +impl StaticFn for StaticTrue { + fn call() -> bool { + true + } +} + +impl StaticFn for StaticFalse { + fn call() -> bool { + false + } +} + +#[delegatable_trait] +pub trait StaticCall { + fn call(&self) -> bool; +} + +pub struct BaseCaller; + +impl StaticCall for BaseCaller { + fn call(&self) -> bool { + C::call() + } +} + +#[derive(Delegate)] +#[delegate(StaticCall)] +pub struct WrappedCaller(BaseCaller); + +fn main() { + let c = WrappedCaller(BaseCaller); + // Verify that the generic type is correctly passed through without relying on type inference. + assert!(c.call::()); + assert!(!c.call::()); +}