Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0214a905d2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let patchable_generic_params = self.collect_patchable_generic_params(); | ||
| for param in self.generics.type_params() { | ||
| if let Some(TypeUsage::Patchable) = self.preserved_types.get(¶m.ident) { | ||
| let crate_root = &self.crate_path; | ||
| bounds.push(quote! { #param: #crate_root :: Patchable }); | ||
| if patchable_generic_params.contains(¶m.ident) { | ||
| bounds.push(quote! { #param: ::core::clone::Clone }); | ||
| } |
There was a problem hiding this comment.
Avoid forcing Clone on generics only used by patchable fields
This adds T: Clone for any generic referenced inside a #[patchable] field type. That over‑constrains cases like struct Outer<T> { #[patchable] inner: Wrapper<T> } where Wrapper<T>: Patchable does not require T: Clone (e.g., PhantomData wrappers or manual Patchable impls whose Patch doesn’t depend on T). The new bound will make such valid uses fail to compile even though Wrapper<T>: Patchable is satisfied.
Useful? React with 👍 / 👎.
Motivation
#[patchable]fields to be simple concrete types and failed for generic wrapper types, preventing derivingPatchablewhen a field uses a type parameter.#[patchable]on fields whose types refer to generic parameters so generated state types and bounds are correct.Description
patchable_field_typesand replace the previousTypeUsageenum with a compactTypeUsage { used_in_keep: bool }to mark types referenced from kept fields.collect_patchable_generic_paramsandis_generic_param_typehelpers to detect generic parameters used by#[patchable]fields and include them in the generated state generics and bounds.<#ty as crate::Patchable>::Patch) while emittingT::Patchfor plain generic parameters, and addPatchablebounds for concrete field types.patchable/src/lib.rsthat verifies#[patchable]works for a field with a generic wrapper type and ensured serde-compatible bounds are emitted as needed.Testing
cargo testwhich compiled the procedural macro and library and executed unit tests; all tests passed (6 passedunit tests, plus doctests).Codex Task