Skip to content

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

Merged
coord-e merged 1 commit into
mainfrom
claude/gifted-bohr-2z2l54
Oct 13, 2026
Merged

coord-e merged 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Tuple-enum patterns can panic during field counting, and the tuple-struct path lacks regression coverage.

2 open findings
What changed in this PR

Fixes annotation bindings after .. in tuple and tuple-struct parameter patterns.

Changes:

  • Adjusts projected field indices using rustc’s pattern helper.
  • Adds paired pass/fail UI regression tests.
File Description
src/​analyze/​annot_fn.rs Corrects field-index calculation after rest patterns.
tests/​ui/​pass/​annot_param_rest_pattern.rs Adds the valid regression case.
tests/​ui/​fail/​annot_param_rest_pattern.rs Adds the invalid regression case.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/analyze/annot_fn.rs
Comment on lines +382 to +386
let pat_ty = self.pat_ty(pat);
let field_count = match pat_ty.ty_adt_def() {
Some(adt) => adt.non_enum_variant().fields.len(),
None => pat_ty.tuple_fields().len(),
};

#[thrust_macros::requires(true)]
#[thrust_macros::ensures(result == d)]
fn last((_a, .., _c, d): (i64, i64, i64, i64)) -> i64 {
@coord-e
coord-e merged commit b2194d8 into main Oct 13, 2026
7 checks passed
@coord-e
coord-e deleted the claude/gifted-bohr-2z2l54 branch October 13, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants