Skip to content

Allow proof blocks inside proof fn (fixes #2061)#2249

Open
nitrotap wants to merge 1 commit into
verus-lang:mainfrom
nitrotap:fix/issue-2061-proof-block-in-proof-fn
Open

Allow proof blocks inside proof fn (fixes #2061)#2249
nitrotap wants to merge 1 commit into
verus-lang:mainfrom
nitrotap:fix/issue-2061-proof-block-in-proof-fn

Conversation

@nitrotap
Copy link
Copy Markdown

Summary

Fixes #2061

proof { } blocks inside proof fn previously produced a confusing error: "proof blocks inside spec code is currently supported only for spec functions with decreases". This was because the macro layer used a single inside_ghost counter for both spec and proof functions, causing proof blocks in proof functions to be incorrectly marked as proof_in_spec.

Changes

  • builtin_macros/src/syntax.rs — Add inside_spec tracking to distinguish spec fn from proof fn. Only emit proof_in_spec for actual spec functions; emit proof_block for proof functions.
  • vir/src/modes.rs — Allow proof blocks when already in ghost mode (redundant but harmless)
  • rust_verify_test/tests/proof_in_spec.rs — Update 3 tests, add 8 new tests for issue bad error msg for proof block in proof fn #2061

Test plan

  • vargo build --release — 1490 verified, 0 errors
  • vargo test --vstd-no-verify -p rust_verify_test --test proof_in_spec — 38 passed
  • vargo test --vstd-no-verify -p rust_verify_test --test modes — 115 passed

@nitrotap nitrotap force-pushed the fix/issue-2061-proof-block-in-proof-fn branch from ce807da to 529659b Compare March 16, 2026 03:56
@Chris-Hawblitzel Chris-Hawblitzel self-requested a review March 29, 2026 22:13
Previously, `proof { }` blocks inside `proof fn` produced a confusing
error: "proof blocks inside spec code is currently supported only for
spec functions with decreases". This was because the macro layer used
a single `inside_ghost` counter for both spec and proof functions.

This fix:
- Adds `inside_spec` tracking to distinguish spec fn from proof fn
- Emits `proof_in_spec` only for spec functions (for termination checking)
- Emits `proof_block` for proof functions (treating them as redundant but allowed)
- Updates modes.rs to allow proof blocks when already in ghost mode
@nitrotap nitrotap force-pushed the fix/issue-2061-proof-block-in-proof-fn branch from 529659b to f8536cf Compare May 15, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bad error msg for proof block in proof fn

1 participant