Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when using a delagateable trait with const generics #58

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ambassador/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,),
}
}

Expand Down Expand Up @@ -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<proc_macro2::Punct> = None;
Expand Down Expand Up @@ -217,6 +217,7 @@ fn build_method(
) -> TokenStream {
quote! {
#[inline]
#[allow(unused_braces)]
#extr_attrs
#method_sig {
#method_invocation
Expand Down
31 changes: 31 additions & 0 deletions ambassador/tests/run-pass/const_generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extern crate ambassador;

use ambassador::{delegatable_trait, Delegate};

#[delegatable_trait]
trait S<const N: usize> {
fn handle(&self, x: [u8; N]);
}

struct Base;

impl<const N: usize> S<N> for Base {
fn handle(&self, x: [u8; N]) {
println!("{x:?}");
}
}

const C: usize = 2;

#[derive(Delegate)]
#[delegate(S<1>)]
#[delegate(S<C>)]
#[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]);
}
Loading