fix: handle PhantomData in enum schema derive#369
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95b9a6c85b
ℹ️ 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".
95b9a6c to
d4f0eb5
Compare
|
Small process note: I force-pushed once to fold in a CI-only fix before review started. Sorry about that. I will avoid rewriting this PR branch from here and use normal follow-up commits for any future changes. |
r-near
left a comment
There was a problem hiding this comment.
Looks mostly fine, just need to handle that Codex comment. Also could you add the mixed param case as a regression test?
|
Confirmed fixed on the new commits. tried my repro again plus a few adversarial variants and they all compile now. Nice that the rewrite also catches params referenced in the predicate's bounds, not just the bounded type. LGTM. :) |
Fixes #329.
This fixes
#[derive(BorshSchema)]for enum variants that containPhantomData<T>.What changed:
PhantomData<T>when enum variant schema params are computedPhantomData<T>skip behavior for the other derive pathsenum Parametrized<T> { Item(PhantomData<T>) }using a marker type that does not implementBorshSchemaWhy:
The struct case already works, but the enum variant case from #329 expands into code that tries to use the outer generic parameter from a generated inner item. I checked this with a throwaway crate: clean
origin/masterfails withE0401, while the patched local Borsh passes and can callMyEnum::<NotSchema>::add_definitions_recursively.Checked:
cargo test -p borsh --features unstable__schema schema::test_phantom_datacargo test -p borsh --features unstable__schema schema::test_generic_enumscargo test -p borsh --features unstable__schemacargo test -p borsh-derive --features schemacargo fmt --checkcargo clippy -p borsh-derive --features schema -- -D warningscargo clippy -p borsh --features unstable__schema -- -D warnings