diff --git a/ambassador/src/register.rs b/ambassador/src/register.rs index 39669fe..0bb7467 100644 --- a/ambassador/src/register.rs +++ b/ambassador/src/register.rs @@ -137,7 +137,7 @@ fn param_to_matcher(param: &GenericParam) -> TokenStream { let ident = &lifetime.ident; quote!($ #ident : lifetime,) } - GenericParam::Const(ConstParam { ident, .. }) => quote!($ #ident : ident,), + GenericParam::Const(ConstParam { ident, .. }) => quote!($ #ident : expr,), } } @@ -181,7 +181,7 @@ fn make_assoc_ty_bound( } } -// Replaces the identifiers in gen_idents with there macro args (X => $X) ('a => $a) +// Replaces the identifiers in gen_idents with their macro args (X => $X) ('a => $a) fn replace_gen_idents(tokens: TokenStream, gen_idents: &[&Ident]) -> TokenStream { let mut res = TokenStream::new(); let mut apostrophe: Option = None; @@ -217,6 +217,7 @@ fn build_method( ) -> TokenStream { quote! { #[inline] + #[allow(unused_braces)] #extr_attrs #method_sig { #method_invocation diff --git a/ambassador/tests/run-pass/const_generic.rs b/ambassador/tests/run-pass/const_generic.rs new file mode 100644 index 0000000..4c00389 --- /dev/null +++ b/ambassador/tests/run-pass/const_generic.rs @@ -0,0 +1,31 @@ +extern crate ambassador; + +use ambassador::{delegatable_trait, Delegate}; + +#[delegatable_trait] +trait S { + fn handle(&self, x: [u8; N]); +} + +struct Base; + +impl S for Base { + fn handle(&self, x: [u8; N]) { + println!("{x:?}"); + } +} + +const C: usize = 2; + +#[derive(Delegate)] +#[delegate(S<1>)] +#[delegate(S)] +#[delegate(S<{C+1}>)] +struct Wrap(Base); + +fn main() { + let w = Wrap(Base); + w.handle([1]); + w.handle([1, 2]); + w.handle([1, 2, 3]); +}