Skip to content

Replace-mode stubs drop an owned receiver even when the real body moves it out #5118

Open

Description

@feliperodri

Found while reviewing #4985 (owned-receiver contracts on const fn).

Problem

In replace mode, a stub from #[kani::stub_verified] always drops an owned receiver, even when the real body moves it out and never drops it.

struct Owned(u32);
impl Drop for Owned { fn drop(&mut self) { DROPS.fetch_add(1, Ordering::Relaxed); } }

impl Owned {
    #[kani::ensures(|result: &Owned| result.0 == old(self.0))]
    fn id(self) -> Owned { self }   // moves `self` out; the real body never drops it
}

#[kani::proof]
#[kani::stub_verified(Owned::id)]
fn check_stub_does_not_drop_moved_receiver() {
    let v: u32 = kani::any();
    let o = Owned(v).id();
    assert!(o.0 == v);
    assert!(DROPS.load(Ordering::Relaxed) == 0);   // FAILS: the stub drops the receiver
}

With the real body, DROPS stays 0. Under the stub it is 1, so the harness fails. A harness that depends on the number of drops can therefore report a spurious failure, or pass when it shouldn't.

Scope

Suggested direction

  • Document the limitation in the contracts reference, so users know that a verified stub's receiver is always dropped.
  • Longer term: make the replace stub drop the receiver only when the body does not move it out (or pin the behaviour with a test that matches the real body's drop).

Reproduced on 8e09e0756 (#4985 head) and on the main base.

Activity

  1. added
    [C] Bug
    on Nov 6, 2026
  2. added this to the Contracts milestone on Nov 6, 2026
  3. self-assigned this
    on Nov 6, 2026
  4. added theissue type on Nov 6, 2026
  5. added
    [F] Spurious Failure
    on Nov 6, 2026
  6. added
    [F] Soundness
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug[F] Soundness[F] Spurious Failure

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions