Skip to content

Commit

Permalink
fix: forward type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jan 20, 2024
1 parent 88f4072 commit eb8e713
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ambassador/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
46 changes: 46 additions & 0 deletions ambassador/tests/run-pass/generic_method.rs
Original file line number Diff line number Diff line change
@@ -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<C: StaticFn>(&self) -> bool;
}

pub struct BaseCaller;

impl StaticCall for BaseCaller {
fn call<C: StaticFn>(&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::<StaticTrue>());
assert!(!c.call::<StaticFalse>());
}

0 comments on commit eb8e713

Please sign in to comment.