Skip to content

Commit

Permalink
fix: Incorrect codegen for const generic params with default
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Dec 20, 2024
1 parent 04a4c14 commit 7c8ad96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 19 additions & 0 deletions fieldx/tests/builder_const_generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use fieldx::fxstruct;

#[fxstruct(builder)]
struct Foo<const N: usize = 1> {
#[fieldx(get, default(N))]
v: usize,
}

#[test]
fn generic_default() {
let foo: Foo = Foo::builder().build().unwrap();
assert_eq!(foo.v, 1, "default generic value is 1");
}

#[test]
fn generic_2() {
let foo = Foo::<2>::builder().build().unwrap();
assert_eq!(foo.v, 2, "generic value is 2");
}
5 changes: 2 additions & 3 deletions fieldx_derive/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ impl FXRewriter {
let builder_ident = ctx.builder_ident();
let builders = ctx.builders_combined();
let input_ident = ctx.input_ident();
let generics = ctx.input().generics();
let where_clause = &generics.where_clause;
let (impl_generics, _, where_clause) = ctx.input().generics().split_for_impl();
let generic_params = ctx.struct_generic_params();
let attributes = ctx.args().builder_impl_attributes();
let post_build_ident = ctx.builder_post_build_ident();
Expand Down Expand Up @@ -398,7 +397,7 @@ impl FXRewriter {

quote![
#attributes
impl #generics #builder_ident #generic_params
impl #impl_generics #builder_ident #generic_params
#where_clause
{
#fn_new
Expand Down

0 comments on commit 7c8ad96

Please sign in to comment.