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
Cannot annotate a const fn taking self by value with a contract (E0493) #4984
with Kani version: 0.68.0 (built from main at 1640445, CBMC 6.11.0).
I expected this to compile, the same way the equivalent typed-argument case already does:
// compiles today:#[kani::requires(*b < 100)]constfntake(b:Box<u32>) -> Box<u32>{ b }
Instead, this happened:
error[E0493]: destructor of `S` cannot be evaluated at compile-time
--> repro.rs:6:17
|
4 | #[kani::requires(*self.0 < 100)]
| - value is dropped here
5 | #[kani::ensures(|result: &S| *result.0 == old(*self.0))]
6 | const fn id(self) -> S {
| ^^^^ the destructor for this type cannot be evaluated in constant functions
The body alone is const-legal: remove the two contract attributes and it compiles. The error appears only with the contract, and only when all three hold together: a const fn, a by-value owned self, and a Self that needs drop. A non-const twin, a Copy receiver, and a typed Box argument all compile.
Use case: proof_for_contract on a const fn with an owned self in std — the case that hit it is Box::<MaybeUninit>::assume_init (const unsafe fn since nightly-2026-09-25); a consumer is model-checking/verify-rust-std#669.
Activity
Move an owned receiver into the replace closure so const fns with con…