Skip to content

Commit 51aa8e0

Browse files
committed
wip
1 parent c109ea8 commit 51aa8e0

File tree

7 files changed

+24
-352
lines changed

7 files changed

+24
-352
lines changed

module/core/former/plan.md

Lines changed: 8 additions & 315 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Run { pub command : String }
1010

1111
// Derive Former on the simplified enum - This should generate static methods
1212
#[ derive( Debug, Clone, PartialEq, former::Former ) ]
13-
// #[ debug ]
13+
#[ debug ]
1414
enum FunctionStep
1515
{
1616
Break( Break ),

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

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn former_for_enum
168168

169169
// <<< Added: Collect detailed field info for the current variant >>>
170170
let variant_field_info: Vec<EnumVariantFieldInfo> = match &variant.fields {
171-
syn::Fields::Named(f) => f.named.iter().enumerate().map(|(_index, field)| { // <<< Use _index
171+
syn::Fields::Named(f) => f.named.iter().map(|field| { // <<< Use _index
172172
let attrs = FieldAttributes::from_attrs(field.attrs.iter())?;
173173
let is_constructor_arg = attrs.arg_for_constructor.value(false);
174174
Ok(EnumVariantFieldInfo {
@@ -216,17 +216,12 @@ pub(super) fn former_for_enum
216216
&mut standalone_constructors,
217217
&variant_attrs,
218218
&variant_field_info,
219-
// Pass Option<&WhereClause> directly
220-
merged_where_clause, // FIX: Pass directly
219+
merged_where_clause,
221220
)?;
222221
},
223222
// Case 2: Tuple variant
224223
syn::Fields::Unnamed( fields ) =>
225224
{
226-
// --- DEBUG PRINT 3b ---
227-
// ...
228-
// --- END DEBUG PRINT 3b ---
229-
230225
if variant_attrs.arg_for_constructor.value( false )
231226
{
232227
return Err( syn::Error::new_spanned( variant, "#[arg_for_constructor] cannot be applied directly to an enum variant identifier. Apply it to the fields *within* the variant instead, e.g., `MyVariant( #[arg_for_constructor] i32 )`." ) );
@@ -252,15 +247,13 @@ pub(super) fn former_for_enum
252247
&mut standalone_constructors,
253248
&variant_attrs,
254249
&variant_field_info,
255-
// Pass Option<&WhereClause> directly
256-
merged_where_clause, // FIX: Pass directly
250+
merged_where_clause,
257251
)?;
258252
}
259253
// Sub-case: Non-zero fields (Tuple(1) or Tuple(N))
260254
_ => // len >= 1
261255
{
262-
// Call the extracted handler for non-zero tuple variants
263-
handle_tuple_non_zero_variant // FIX: Corrected call
256+
handle_tuple_non_zero_variant
264257
(
265258
ast,
266259
variant,
@@ -275,31 +268,24 @@ pub(super) fn former_for_enum
275268
&mut standalone_constructors,
276269
&variant_attrs,
277270
&variant_field_info,
278-
merged_where_clause, // Pass Option<&WhereClause> directly
271+
merged_where_clause,
279272
)?;
280273
}
281274
}
282275
},
283276
// Case 3: Struct variant
284-
syn::Fields::Named( fields ) => // <<< Use fields variable >>>
277+
syn::Fields::Named( fields ) =>
285278
{
286-
// --- DEBUG PRINT 3c ---
287-
// ...
288-
// --- END DEBUG PRINT 3c ---
289-
290279
if variant_attrs.arg_for_constructor.value( false )
291280
{
292281
return Err( syn::Error::new_spanned( variant, "#[arg_for_constructor] cannot be applied directly to an enum variant identifier. Apply it to the fields *within* the variant instead, e.g., `MyVariant { #[arg_for_constructor] field : i32 }`." ) );
293282
}
294283

295-
// <<< Start: Logic for Named Fields (Struct-like Variants) >>>
296-
println!( "DEBUG: Processing Named fields for variant: {}", variant.ident ); // Debug print
297284
match fields.named.len()
298285
{
299286
// Sub-case: Zero fields (Struct(0))
300287
0 =>
301288
{
302-
println!( "DEBUG: Calling handle_struct_zero_variant for variant: {}", variant.ident ); // Debug print
303289
handle_struct_zero_variant
304290
(
305291
ast,
@@ -315,15 +301,12 @@ pub(super) fn former_for_enum
315301
&mut standalone_constructors,
316302
&variant_attrs,
317303
&variant_field_info,
318-
// Pass Option<&WhereClause> directly
319-
merged_where_clause, // FIX: Pass directly
304+
merged_where_clause,
320305
)?;
321306
}
322307
// Sub-case: Single field (Struct(1)) or Multi-field (Struct(N))
323308
_ => // len >= 1
324309
{
325-
// Call the extracted handler for non-zero struct variants
326-
println!( "DEBUG: Calling handle_struct_non_zero_variant for variant: {}", variant.ident ); // Debug print
327310
handle_struct_non_zero_variant
328311
(
329312
ast,
@@ -339,14 +322,13 @@ pub(super) fn former_for_enum
339322
&mut standalone_constructors,
340323
&variant_attrs,
341324
&variant_field_info,
342-
// Pass Option<&WhereClause> directly
343-
merged_where_clause, // FIX: Pass directly
325+
merged_where_clause,
344326
)?;
345327
}
346328
}
347-
} // End syn::Fields::Named
348-
} // End match variant.fields
349-
} // End variant loop
329+
}
330+
}
331+
}
350332

351333
// Assemble the final impl block containing the generated static methods
352334
let result = quote!

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Result< () >
6767
if has_debug
6868
{
6969
let about = format!( "derive : Former\nenum : {enum_name}\nvariant : {variant_name_str}\nhandler : struct_zero" );
70-
diag::report_print( about, original_input, &methods.last().unwrap() ); // Print the generated method
70+
diag::report_print( about, original_input, methods.last().unwrap() ); // Print the generated method
7171
}
7272

7373
Ok( () )

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use syn::
1414
{
1515
self,
1616
Fields,
17-
Error,
1817
GenericParam,
1918
TypeParam,
2019
ConstParam,
@@ -99,9 +98,7 @@ pub( super ) fn handle_tuple_non_zero_variant< 'a >
9998
if !matches!( inner_type, syn::Type::Path( _ ) ) { return Err( syn::Error::new_spanned( inner_type, "#[subform_scalar] can only be applied to variants holding a path type (e.g., MyStruct, Option<T>), not tuples, references, etc." ) ); }
10099
}
101100
else // Default case
102-
{
103-
if !matches!( inner_type, syn::Type::Path( _ ) ) { return Err( syn::Error::new_spanned( inner_type, "Default subforming requires the single field of a tuple variant to be a path type (e.g., MyStruct, Option<T>)." ) ); }
104-
}
101+
if !matches!( inner_type, syn::Type::Path( _ ) ) { return Err( syn::Error::new_spanned( inner_type, "Default subforming requires the single field of a tuple variant to be a path type (e.g., MyStruct, Option<T>)." ) ); }
105102

106103
let end_struct_name = format_ident!( "{}{}End", enum_name, variant_ident );
107104
let ( inner_type_name, inner_generics ) = match inner_type { syn::Type::Path( tp ) => { let s = tp.path.segments.last().unwrap(); ( s.ident.clone(), s.arguments.clone() ) }, _ => unreachable!() };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Result< () >
6161
if has_debug
6262
{
6363
let about = format!( "derive : Former\nenum : {enum_name}\nvariant : {variant_name_str}\nhandler : tuple_zero" );
64-
diag::report_print( about, original_input, &methods.last().unwrap() ); // Print the generated method
64+
diag::report_print( about, original_input, methods.last().unwrap() ); // Print the generated method
6565
}
6666

6767
Ok( () )

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Result< () >
6262
if has_debug
6363
{
6464
let about = format!( "derive : Former\nenum : {enum_name}\nvariant : {variant_name_str}\nhandler : unit" );
65-
diag::report_print( about, original_input, &methods.last().unwrap() ); // Print the generated method
65+
diag::report_print( about, original_input, methods.last().unwrap() ); // Print the generated method
6666
}
6767

6868
Ok( () )

0 commit comments

Comments
 (0)