From ba865b581fbc1d0589b402b028f2bce70332891b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 1 Apr 2023 15:00:06 +0200 Subject: feat: allow for usage of associated types of generics --- macros/src/expectation.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'macros/src') diff --git a/macros/src/expectation.rs b/macros/src/expectation.rs index 8120cfd..2e86db0 100644 --- a/macros/src/expectation.rs +++ b/macros/src/expectation.rs @@ -180,7 +180,6 @@ impl Expectation ident: Ident, generics: Generics, phantom_fields: &[PhantomField], - returning_fn: &Type, boxed_predicate_types: &[Type], ) -> ItemStruct { @@ -208,7 +207,9 @@ impl Expectation format_ident!("Option"), Some(AngleBracketedGenericArguments::new( WithColons::No, - [GenericArgument::Type(returning_fn.clone())], + [GenericArgument::Type(Type::BareFn( + TypeBareFn::new([], ReturnType::Default), + ))], )), )], ))), @@ -345,7 +346,6 @@ impl ToTokens for Expectation self.ident.clone(), generics.clone(), phantom_fields, - &returning_fn, &boxed_predicate_types, ); @@ -445,7 +445,7 @@ impl ToTokens for Expectation func: #returning_fn ) -> &mut Self { - self.returning = Some(func); + self.returning = Some(unsafe { std::mem::transmute(func) }); self } @@ -536,7 +536,9 @@ impl ToTokens for Expectation self.call_cnt.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - returning + let returning_ptr: *const _ = returning; + + unsafe { &*returning_ptr.cast()} } } -- cgit v1.2.3-18-g5258