Skip to content

Commit f406a3e

Browse files
committed
variadic_from wip
1 parent 4187741 commit f406a3e

27 files changed

+479
-860
lines changed

module/core/variadic_from/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55

66
* **2025-07-01:**
77
* Generalized `CONTRIBUTING.md` to be about all crates of the `wTools` repository, including updating the title, removing specific crate paths, and generalizing commit message examples.
8+
9+
* [2025-07-06] Refactored `variadic_from_meta` to align with spec v1.1.

module/core/variadic_from/src/lib.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -60,53 +60,6 @@ pub mod variadic
6060
compile_error!( "Too many arguments" );
6161
};
6262
}
63-
/// Blanket implementation for `From1` for single-element tuples.
64-
#[ cfg( feature = "type_variadic_from" ) ]
65-
impl< T, All > From1< ( T, ) > for All
66-
where
67-
All : From1< T >,
68-
{
69-
fn from1( a1 : ( T, ) ) -> Self
70-
{
71-
All::from1( a1.0 )
72-
}
73-
}
74-
75-
/// Blanket implementation for `From1` for two-element tuples.
76-
#[ cfg( feature = "type_variadic_from" ) ]
77-
impl< T1, T2, All > From1< ( T1, T2 ) > for All
78-
where
79-
All : From2< T1, T2 >,
80-
{
81-
fn from1( a1 : ( T1, T2 ) ) -> Self
82-
{
83-
All::from2( a1.0, a1.1 )
84-
}
85-
}
86-
87-
/// Blanket implementation for `From1` for three-element tuples.
88-
#[ cfg( feature = "type_variadic_from" ) ]
89-
impl< T1, T2, T3, All > From1< ( T1, T2, T3 ) > for All
90-
where
91-
All : From3< T1, T2, T3 >,
92-
{
93-
fn from1( a1 : ( T1, T2, T3 ) ) -> Self
94-
{
95-
All::from3( a1.0, a1.1, a1.2 )
96-
}
97-
}
98-
99-
/// Blanket implementation for `From1` for unit type.
100-
#[ cfg( feature = "type_variadic_from" ) ]
101-
impl< All > From1< () > for All
102-
where
103-
All : core::default::Default,
104-
{
105-
fn from1( _a1 : () ) -> Self
106-
{
107-
core::default::Default::default()
108-
}
109-
}
11063
}
11164

11265
/// Namespace with dependencies.

module/core/variadic_from/task_plan.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* **Overall Progress:** 1/4 increments complete
1616
* **Increment Status:**
1717
* ✅ Increment 1: Refactor `variadic_from_meta` for Spec Compliance
18-
* Increment 2: Overhaul and Restructure Test Suite
18+
* Increment 2: Overhaul and Restructure Test Suite
1919
* ⚫ Increment 3: Refactor `variadic_from` Library and Update `Readme.md`
2020
* ⚫ Increment 4: Finalization
2121

@@ -26,6 +26,7 @@
2626
* **Additional Editable Crates:**
2727
* `module/core/variadic_from_meta`
2828

29+
* [Increment 2 | 2025-07-06 09:34 UTC] Fixed `quote!` macro repetition issues in `variadic_from_meta/src/lib.rs` by using direct indexing for arguments and types.
2930
### Relevant Context
3031
* **Specification:** `module/core/variadic_from/spec.md`
3132
* **Codestyle:** `code/rules/codestyle.md`
@@ -113,6 +114,28 @@
113114
* All steps of the `Crate Conformance Check Procedure` must pass with exit code 0 and no warnings.
114115
* **Commit Message:** `chore(variadic_from): Finalize and verify spec v1.1 implementation`
115116

117+
### Test Re-enabling Sequence
118+
To systematically re-enable and debug the tests, follow this sequence:
119+
120+
1. **Re-enable `derive_test.rs` (Basic Functionality):**
121+
* Uncomment `mod derive_test;` in `module/core/variadic_from/tests/inc/mod.rs`.
122+
* Run `cargo test -p variadic_from --test variadic_from_tests`.
123+
* Address any compilation or runtime errors. Pay close attention to `E0282` (type annotations needed) for `from!` macro calls. If these persist, consider adding explicit type annotations to the `let x = from!(...);` lines in `derive_test.rs` as a temporary measure or if the macro cannot infer the type.
124+
2. **Re-enable `err_from_0_fields.rs` (Compile-Fail: 0 Fields):**
125+
* Uncomment `mod err_from_0_fields;` in `module/core/variadic_from/tests/inc/mod.rs`.
126+
* Run `cargo test -p variadic_from --test variadic_from_tests`.
127+
* Verify that it fails with the expected error message: "VariadicFrom can only be derived for structs with named or unnamed fields."
128+
3. **Re-enable `err_from_4_fields.rs` (Compile-Fail: >3 Fields):**
129+
* Uncomment `mod err_from_4_fields;` in `module/core/variadic_from/tests/inc/mod.rs`.
130+
* Run `cargo test -p variadic_from --test variadic_from_tests`.
131+
* Verify that it fails with the expected error message: "Too many arguments".
132+
### Notes & Insights
133+
* **`quote!` Macro Repetition Issues:** Repeatedly encountered `E0277` (`Dlist<...>: ToTokens` not satisfied) and `E0599` (`quote_into_iter` not found) when attempting to use `quote!`'s repetition syntax (`#( ... ),*`) with direct indexing into `Vec<Ident>` or `Vec<&Type>`. The solution was to extract individual elements into separate local variables before passing them to `quote!`. This indicates `quote!` expects concrete `ToTokens` implementors for each `#var` interpolation, not an iterable that it then tries to index.
134+
* **`FromN` Trait Return Type:** The generated `fromN` methods were initially returning `()` instead of `Self`, leading to `E0053` and `E0308` errors. This was fixed by explicitly adding `-> Self` to the function signatures in the `quote!` macro.
135+
* **Conflicting Blanket Implementations:** The `module/core/variadic_from/src/lib.rs` contained blanket `From1` implementations for tuples and unit types. These conflicted with the specific `FromN` implementations generated by the `VariadicFrom` derive macro, causing `E0119` (conflicting implementations). The resolution was to remove these blanket implementations, as the derive macro now handles all necessary `From` and `FromN` implementations.
136+
* **Generics Propagation:** Initial attempts to generate `impl` blocks for generic structs did not correctly propagate the generic parameters and `where` clauses, leading to `E0412` (`cannot find type T in this scope`) and `E0107` (`missing generics for struct`). This was resolved by storing `&syn::Generics` in `VariadicFromContext` and using `generics.split_for_impl()` to correctly apply `impl_generics`, `ty_generics`, and `where_clause` to the generated `impl` blocks.
137+
* **`from!` Macro Type Inference:** After fixing the above, `E0282` (`type annotations needed`) errors appeared for `from!` macro calls. This is likely due to the compiler's inability to infer the target type when multiple `FromN` traits might apply, especially after removing the blanket implementations. This will need to be addressed by either adding explicit type annotations in the tests or by refining the `from!` macro's dispatch if possible.
138+
* **Compile-Fail Tests:** `err_from_0_fields.rs` and `err_from_4_fields.rs` are correctly failing as expected, confirming the macro's validation logic for field counts.
116139
### Changelog
117140
* [New Plan | 2025-07-05 23:13 UTC] Created a new, comprehensive plan to address spec compliance, test suite overhaul, and documentation accuracy for `variadic_from` and `variadic_from_meta`.
118141
* [2025-07-06] Refactored `variadic_from_meta` to align with spec v1.1, including `Cargo.toml` updates, modular code generation, delegation, conditional convenience impls, and absolute paths. Resolved all compilation errors and lints.

module/core/variadic_from/tests/inc/auto_std_named_derive.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

module/core/variadic_from/tests/inc/auto_std_named_manual.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! This test ensures that `VariadicFrom` derive fails for structs with 0 fields.
2+
3+
use variadic_from::VariadicFrom;
4+
use variadic_from::from;
5+
6+
#[ derive( VariadicFrom ) ]
7+
struct MyStruct;
8+
9+
fn main()
10+
{
11+
let _x = from!( 1 ); // This should cause a compile error
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! This test ensures that `VariadicFrom` derive fails for structs with >3 fields.
2+
3+
use variadic_from::VariadicFrom;
4+
use variadic_from::from;
5+
6+
#[ derive( VariadicFrom ) ]
7+
struct MyStruct( i32, i32, i32, i32 );
8+
9+
fn main()
10+
{
11+
let _x = from!( 1, 2, 3, 4 ); // This should cause a compile error
12+
}

0 commit comments

Comments
 (0)