Skip to content

Adjust field indices past .. in spec parameter patterns - #326

Open
coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-2z2l54
Open

coord-e wants to merge 1 commit into
mainfrom
claude/gifted-bohr-2z2l54

Conversation

@coord-e

@coord-e coord-e commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Fixes #325.

AnnotFnTranslator::build_env_from_pat bound a tuple or tuple-struct parameter pattern's sub-patterns with a plain enumerate() and ignored the pattern's .. rest. As a result, every binding after the rest referred to the wrong field in requires/ensures. For example, in (a, .., c): (i64, i64, i64) the spec's c was tuple_proj(1). A #[thrust::trusted] spec was then assumed about the wrong field, which made panicking programs verify as safe. Correct programs were also rejected.

This change shifts the indices past the rest with rustc_hir::pat_util::EnumerateAndAdjustIterator::enumerate_and_adjust, the helper rustc's own pattern handling uses. The field count comes from the pattern's type.

Tests

tests/ui/{pass,fail}/annot_param_rest_pattern.rs destructure (_a, .., _c, d) and state ensures(result == d). The two files differ only in the body (d vs _c). Before this change, the pair fails in both directions: pass is rejected with Unsat, and fail verifies because the spec's d was mapped to the body's _c.

cargo fmt --check, cargo clippy -- -D warnings, and cargo test (396 UI tests, with PCSat) all pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_014QLtzjY5sB9iS1pK4nJixa


Generated by Claude Code

build_env_from_pat enumerated a tuple or tuple-struct pattern's
sub-patterns directly, ignoring its `..` rest, so every binding after
the rest was bound to the wrong field in requires/ensures: in
`(a, .., c): (i64, i64, i64)`, the spec's `c` denoted field 1. Shift
the indices past the rest with rustc's enumerate_and_adjust, as rustc's
own pattern lowering does.

Fixes #325

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014QLtzjY5sB9iS1pK4nJixa
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T21:54:26.497511Z 9b225a6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b225a6590

ℹ️ 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".

Comment thread src/analyze/annot_fn.rs
PatKind::TupleStruct(_, subpats, dotdot_pos) | PatKind::Tuple(subpats, dotdot_pos) => {
let pat_ty = self.pat_ty(pat);
let field_count = match pat_ty.ty_adt_def() {
Some(adt) => adt.non_enum_variant().fields.len(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Select the matched enum variant before counting fields

When an annotated function uses an irrefutable tuple-style enum pattern, such as a single-variant enum E { V(i32) } with fn f(E::V(_): E), the generated formula function preserves that parameter pattern and reaches this branch. Its pattern type returns the enum AdtDef, but non_enum_variant() is only valid for structs/unions and panics for enums, so translating even a trivial requires(true) now ICEs despite no .. being present. Resolve the tuple-struct pattern's matched variant and count that variant's fields instead.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants