Skip to content

Commit 505dd46

Browse files
committed
wip
1 parent 5498f4b commit 505dd46

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

module/core/former/tests/inc/former_enum_tests/enum_named_fields_derive.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ pub struct InnerForSubform {
1212
#[ debug ]
1313
pub enum EnumWithNamedFields
1414
{
15-
// --- Unit Variant ---
16-
// Expect: unit_variant_default() -> Enum (Default is scalar for unit)
17-
UnitVariantDefault, // Renamed from UnitVariant
18-
#[ scalar ] // Expect: unit_variant_scalar() -> Enum
19-
UnitVariantScalar, // New
20-
21-
// --- Zero Fields (Named - Struct-like) ---
22-
// VariantZeroDefault {}, // Expect: Compile Error (No #[scalar]) - Cannot test directly
23-
#[ scalar ] // Expect: variant_zero_scalar() -> Enum
24-
VariantZeroScalar {},
25-
26-
// --- Zero Fields (Unnamed - Tuple-like) ---
27-
VariantZeroUnnamedDefault(), // Expect: variant_zero_unnamed_default() -> Enum (Default is scalar for 0 fields)
28-
#[ scalar ] // Expect: variant_zero_unnamed_scalar() -> Enum
29-
VariantZeroUnnamedScalar(),
30-
31-
// --- One Field (Named - Struct-like) ---
32-
// Expect: variant_one_default() -> InnerForSubformFormer<...> (Default behavior for single field is subform)
33-
VariantOneDefault { field_c : InnerForSubform },
34-
#[ scalar ] // Expect: variant_one_scalar( String ) -> Enum
35-
VariantOneScalar { field_a : String },
36-
#[ subform_scalar ] // Expect: variant_one_subform() -> InnerForSubformFormer<...>
37-
VariantOneSubform { field_b : InnerForSubform },
15+
// // --- Unit Variant ---
16+
// // Expect: unit_variant_default() -> Enum (Default is scalar for unit)
17+
// UnitVariantDefault, // Renamed from UnitVariant
18+
// #[ scalar ] // Expect: unit_variant_scalar() -> Enum
19+
// UnitVariantScalar, // New
20+
//
21+
// // --- Zero Fields (Named - Struct-like) ---
22+
// // VariantZeroDefault {}, // Expect: Compile Error (No #[scalar]) - Cannot test directly
23+
// #[ scalar ] // Expect: variant_zero_scalar() -> Enum
24+
// VariantZeroScalar {},
25+
//
26+
// // --- Zero Fields (Unnamed - Tuple-like) ---
27+
// VariantZeroUnnamedDefault(), // Expect: variant_zero_unnamed_default() -> Enum (Default is scalar for 0 fields)
28+
// #[ scalar ] // Expect: variant_zero_unnamed_scalar() -> Enum
29+
// VariantZeroUnnamedScalar(),
30+
31+
// // --- One Field (Named - Struct-like) ---
32+
// // Expect: variant_one_default() -> InnerForSubformFormer<...> (Default behavior for single field is subform)
33+
// VariantOneDefault { field_c : InnerForSubform },
34+
// #[ scalar ] // Expect: variant_one_scalar( String ) -> Enum
35+
// VariantOneScalar { field_a : String },
36+
// #[ subform_scalar ] // Expect: variant_one_subform() -> InnerForSubformFormer<...>
37+
// VariantOneSubform { field_b : InnerForSubform },
3838

3939
// // --- Two Fields (Named - Struct-like) --- (Commented out for isolation)
4040
// // // VariantTwoDefault { field_f : i32, field_g : bool }, // Expect: Compile Error (No #[scalar]) - Cannot test directly

module/core/former_meta/src/derive_former/former_enum/struct_non_zero.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ pub( super ) fn handle_struct_non_zero_variant
760760
def_types_bound_generics_vec.push( formed_param );
761761
let def_types_bound_generics = Punctuated::<_, Comma>::from_iter( def_types_bound_generics_vec );
762762

763-
where_clause_with_end_bound = quote! { #where_clause_with_end_bound End2 : former::FormingEnd< #def_types_name< #def_types_bound_generics > > }; // Use constructed list
763+
where_clause_with_end_bound = quote! { #where_clause_with_end_bound End2 : former::FormingEnd< #def_types_name< Context2, Formed2 > > }; // Use generic parameters directly
764764

765765
quote!
766766
{
@@ -806,7 +806,7 @@ pub( super ) fn handle_struct_non_zero_variant
806806
def_types_bound_generics_vec.push( context_param.clone() );
807807
def_types_bound_generics_vec.push( formed_param.clone() );
808808
let def_types_bound_generics = Punctuated::<_, Comma>::from_iter( def_types_bound_generics_vec );
809-
former_where_predicates.push( parse_quote!{ Definition::Types : former::FormerDefinitionTypes< Storage = #storage_struct_name< #enum_generics_ty_no_comma >, Context = (), Formed = #enum_name< #enum_generics_ty_no_comma > > } ); // Use no_comma, () and EnumName for Context/Formed
809+
former_where_predicates.push( parse_quote!{ Definition::Types : former::FormerDefinitionTypes< Storage = #storage_struct_name< #enum_generics_ty_no_comma >, Context = Context2, Formed = Formed2 > } ); // Use generic parameters directly
810810
// Add FormerMutator bound
811811
former_where_predicates.push( parse_quote!{ Definition::Types : former::FormerMutator } );
812812
// Add enum's original where clause predicates
@@ -886,7 +886,6 @@ pub( super ) fn handle_struct_non_zero_variant
886886
impl< #former_generics_impl > #former_name < #former_generics_ty_no_comma > // Use no_comma
887887
where #former_impl_where_clause // Use the constructed where clause with bounds
888888
{
889-
use former::FormingEnd; // Bring FormingEnd trait into scope
890889
// Standard former methods (new, begin, form, end) - Adjusted to use Definition::Types
891890
#[ inline( always ) ] pub fn new( on_end : Definition::End ) -> Self { Self::begin( None, None, on_end ) }
892891
#[ inline( always ) ] pub fn new_coercing< IntoEnd >( end : IntoEnd ) -> Self where IntoEnd : Into< Definition::End > { Self::begin_coercing( None, None, end ) }
@@ -966,33 +965,38 @@ pub( super ) fn handle_struct_non_zero_variant
966965
quote!
967966
{
968967
#[ automatically_derived ]
969-
impl< #enum_generics_impl > former::FormingEnd
968+
impl< #enum_generics_impl, Context2, Formed2 > former::FormingEnd
970969
<
971970
// Correct generics usage and add comma_if_enum_generics
972-
#def_types_name< #forming_end_def_types_generics > // Use constructed list
971+
#def_types_name< Context2, Formed2 > // Use generic parameters directly
973972
>
974973
for #end_struct_name < #enum_generics_ty_no_comma > // Use no_comma
975-
#where_clause_tokens
974+
where
975+
Context2 : 'static, // Placeholder bound
976+
Formed2 : 'static, // Placeholder bound
977+
#where_clause_tokens // Include original where clause
976978
{
977979
#[ inline( always ) ]
978980
fn call
979981
(
980982
&self,
981983
sub_storage : #storage_struct_name< #enum_generics_ty_no_comma >, // Use no_comma
982-
_context : Option< () >,
984+
_context : Option< Context2 >, // Use Context2 generic parameter
983985
)
984986
->
985987
#enum_name< #enum_generics_ty_no_comma > // Use no_comma
986988
{
987989
// Correctly destructure the tuple from preform and use field names
988990
let preformed_tuple = former::StoragePreform::preform( sub_storage );
991+
// Destructure the tuple into named fields
992+
let ( #( #field_idents_for_construction ),* ) = preformed_tuple;
989993
#enum_name::#variant_ident
990994
{
991-
#( #field_idents_for_construction : preformed_tuple.#tuple_indices ),* // Construct using field names
995+
#( #field_idents_for_construction ),* // Use the bound variables
992996
}
993-
}
994-
}
995-
}
997+
}
998+
}
999+
}
9961000
};
9971001
ctx.end_impls.push( forming_end_impl_tokens );
9981002
// --- Generate Static Method ---

0 commit comments

Comments
 (0)