You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Panic clauses: destructors of by-value arguments run after the panic permission is restored #5221
With the panics_only_if and panics_if contract clauses (#4230), a panic in the destructor of a by-value argument that the function body does not move out is checked against the wrong permission. Kani's contract instrumentation drops such arguments after the check closure has returned, so the drop happens after the function's panic permission is restored and after panics_if has checked the return.
structBomb(bool);implDropforBomb{fndrop(&mutself){ifself.0{panic!("boom")}}}#[kani::panics_only_if(true)]fnunused(_b:Bomb){}#[kani::proof_for_contract(unused)]fncheck_unused(){unused(Bomb(kani::any()));}// FAILED: boom (not permitted by the contract)#[kani::panics_if(armed)]fnmust(armed:bool,_b:Bomb){let _ = armed;}#[kani::proof_for_contract(must)]fncheck_must(){let a:bool = kani::any();must(a,Bomb(a));}// FAILED: returned although `panics_if(armed)` held
The same happens when the body only borrows the argument (fn used(b: Bomb) { let _x = &b; }).
In Rust, these destructors run at the end of the function, so their panics are panics of the function: both harnesses should verify. The current behavior can only cause spurious failures, never hide a panic, and it is documented as a known limitation in the contracts module docs.
A fix needs the check closure to drop the function's by-value arguments before it restores the panic permission and checks the return. That requires a change to how the contract instrumentation passes arguments to the function body.
Activity
Add panics_only_if and panics_if contract clauses (model-checking#4230)