feat(v2): Compile-time required constraints for AnchorAccount#4503
Open
chop0 wants to merge 2 commits into
Open
feat(v2): Compile-time required constraints for AnchorAccount#4503chop0 wants to merge 2 commits into
chop0 wants to merge 2 commits into
Conversation
|
@chop0 is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Can you fix the compile-fail test issues? |
Contributor
|
@chop0 id be happy to help with the compile tests if you want, i saw in the discord u were gonna take a look this morning, but if you want me to help out let me know |
Custom AnchorAccount types can now declare a type-level list of AccountConstraint markers that every #[account(...)] usage must apply. The derive macro emits a const-block superset assertion per field; missing required constraints fail to compile. - traits.rs: ConstraintList, Find<C, Idx> (frunk Here/There index trick), IsSuperset<R, I>, plus required_constraints![] helper macro. - AnchorAccount gains `type RequiredConstraints: ConstraintList`. Built-in wrappers default to (); Box<T> forwards from inner T. - derive: per-field assertion built from attrs.namespaced and spliced beside the impl TryAccounts block. - tests-v2/programs/custom-constraints: TestAccount<T> (1 required) and TestMultiAccount<T> (2 required) wrappers + handlers covering single, multi (reverse-order), Box<TestAccount> forwarding, update(...) satisfaction. - tests-v2/tests/ui_required_constraints: trybuild compile-fail snapshots for missing and partial requirements.
…doctests trybuild compares the full stderr text including rustc-version-specific trait-suggestion formatting and the surrounding `unexpected_cfg` warning. The snapshots captured locally don't match CI's rustc, causing the ui_required_constraints test to fail. Replace with `compile_fail` doctests on `IsSuperset` in lang-v2/src/traits.rs. These verify the trait machinery rejects missing-required and partial-coverage provided lists without comparing stderr text — stable across rustc versions. The positive-case verification continues to be the custom-constraints test crate's handler structs (HandleRequired, HandleRequiredMulti, etc.) compiling. - Remove tests-v2/tests/ui_required_constraints/ and the test driver. - Remove trybuild from tests-v2 dev-dependencies. - Add 3 doctests on IsSuperset: one positive (superset works) and two compile_fail (missing single, missing one of two).
b2af1d6 to
58a4fa2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Custom AnchorAccount types can now declare a type-level list of AccountConstraint markers that every #[account(...)] usage must apply. The derive macro emits a const-block superset assertion per field; missing required constraints fail to compile.
type RequiredConstraints: ConstraintList. Built-in wrappers default to (); Box forwards from inner T.