Reject context-dependent enum discriminants - #3631
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3631 +/- ##
=======================================
Coverage 91.86% 91.86%
=======================================
Files 20 20
Lines 6097 6097
=======================================
Hits 5601 5601
Misses 496 496 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab71f17c6c
ℹ️ 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".
ab71f17 to
0724207
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
0724207 to
ac19a3c
Compare
|
@codex review Authored by an AI agent acting on Josh Liebow-Feeser's behalf. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac19a3c009
ℹ️ 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".
ac19a3c to
219b88e
Compare
|
@codex review Authored by an AI agent acting on Josh Liebow-Feeser's behalf. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
We should be able to support this by scanning and normalizing any |
There was a problem hiding this comment.
Did you miss #3631 (comment)? Make sure to check top-level comments too.
There was a problem hiding this comment.
Authored by an AI agent acting on Josh Liebow-Feeser's behalf.
I did miss the top-level comment on the earlier pass. I have now fetched the complete top-level conversation as well as inline threads, investigated the proposed normalization, and replied with the language-level counterexample here: #3631 (comment)
|
Authored by an AI agent acting on Josh Liebow-Feeser's behalf. I investigated the scope-aware rewrite. We can mechanically distinguish outer A concrete accepted counterexample is: #![feature(core_intrinsics)]
#![allow(internal_features)]
#[repr(u8)]
enum Packet {
Flag(bool) = Self::tag(),
Raw(u8),
}
impl Packet {
const fn tag() -> u8 {
core::intrinsics::is_val_statically_known(0) as u8
}
}The official intrinsic contract says this safe const fn nondeterministically returns The nested-item case has another independent problem: copying the block creates fresh nominal and anonymous types. Their I could not find a stable way around the second evaluation for data-bearing enums. The Reference specifies that For that reason, I think the current positive grammar is the necessary conservative boundary for this derive/helper architecture. We can add individual forms only when their repeatability is proved. Full support would require numeric discriminant reflection from the compiler or a source-owning macro/API that defines the source and validation tags from one canonical evaluation; a derive cannot retroactively rewrite the source enum. A separate fieldless-enum path could use casts of the original variants, but it would not solve the data-bearing case in #3619. |
Derives that validate enum tags copy explicit discriminants into a helper enum. Context-dependent expressions can evaluate differently in that helper, allowing the generated validator to accept an invalid original-enum tag. Restrict copied discriminants to a compiler-defined, repeatable grammar of integer and byte literals with primitive arithmetic and bitwise operations. Reject paths, macros, calls, casts, attributes, and other context-bearing forms before emitting any unsafe impl. Preserve the skip-on-error dependency chain for exhaustive enums, including fieldful variants whose zero tag cannot be identified syntactically, and add cross-toolchain regressions. Closes #3619 *Authored by an AI agent acting on Josh Liebow-Feeser's behalf.* gherrit-pr-id: Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck
219b88e to
65f60cb
Compare
|
@codex review Please review exact head Authored by an AI agent acting on Josh Liebow-Feeser's behalf. |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Derives that validate enum tags copy explicit discriminants into a helper
enum. Context-dependent expressions can evaluate differently in that helper,
allowing the generated validator to accept an invalid original-enum tag.
Restrict copied discriminants to a compiler-defined, repeatable grammar of
integer and byte literals with primitive arithmetic and bitwise operations.
Reject paths, macros, calls, casts, attributes, and other context-bearing
forms before emitting any unsafe impl. Preserve the skip-on-error dependency
chain for exhaustive enums, including fieldful variants whose zero tag cannot
be identified syntactically, and add cross-toolchain regressions.
Closes #3619
Authored by an AI agent acting on Josh Liebow-Feeser's behalf.
Latest Update: v10 — Compare vs v9
📚 Full Patch History
Links show the diff between the row version and the column version.
⬇️ Download this PR
Branch
git fetch origin refs/heads/Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck && git checkout -b pr-Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck FETCH_HEADCheckout
git fetch origin refs/heads/Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck && git checkout FETCH_HEADCherry Pick
git fetch origin refs/heads/Gifjr6pbpu4fh6t7qbzuuqczj3odny3ck && git cherry-pick FETCH_HEADPull
Stacked PRs enabled by GHerrit.