Repository navigation
Preserve specialization default in function contract attributes - #5153
feliperodri merged 1 commit into
Conversation
Parse annotated functions directly as syn::ImplItemFn and preserve default through initial and stacked contract expansions. Keep contracts attached to their annotated implementation. Cover specialization contract clauses, both clause orders with verified stubs, generic methods, old expressions, and expected contract violations. Disable contract assertions in the invalid-caller regression so its expected precondition failure depends on the verified stub. Resolves model-checking#5116
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @Tiramisu-Cake, this is a clean fix for #5116.
syn::ImplItemFn is ItemFn plus defaultness, so parsing the annotated item as ImplItemFn and emitting #vis #defaultness #sig keeps default through the first expansion. The later expansions (handle_expanded) re-emit the whole item, so default survives when there are several contract attributes. Free functions still parse the same way, and a stray default on a free function still gets rustc's usual error, because we pass it through instead of dropping it.
I checked it locally:
- All 9 new tests pass (14 harnesses plus the 5 expected-output tests).
- With the base macros,
specialization_default_fn_5116.rsfails with E0520 (small_sort… not markeddefault), so the test does exercise the fix. - No regressions in the existing contract suites:
kani/FunctionContractshas 22 passed and 0 failed;expected/function-contracthas 134 passed and 0 failed.
The tests are thorough. I liked that they cover stub_verified on the default impl, an override with its own contract, an override without a contract, old(), and a method-local generic FnMut.
The red macos-14 jobs are a runner-configuration issue (macos-14-arm64-us-default is not supported) and don't block this PR.
063204a
#[kani::requires],#[kani::ensures], and#[kani::modifies]fail to parse a specializationdefault fnbecausesyn::ItemFndoes not accept thedefaultkeyword. Parse the function withsyn::ImplItemFnand preservedefaultthrough the initial and subsequent macro expansions. An override still needs its own contract to be aproof_for_contracttarget.The regression tests reproduce the blanket
SmallSortimpl from #5116 and cover individual and stacked clauses,old, and generic methods withproof_for_contractandstub_verified. The expected-output tests check contract violations and the diagnostic for an override without a contract.Testing
syn::ImplItemFn) also passed the nine new cases and ten existing tests in a targeted compiletest run on Linux with the patch applied tof046b70644.Resolves #5116
Disclosure: this change and description were prepared with AI assistance.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.