Skip to content

Error when annotating an associated function with a contract #3206

@zhassan-aws

Description

@zhassan-aws

I tried this code:

extern crate kani;

#[derive(PartialEq, Eq)]
enum Foo {
    A,
    B,
}

impl Foo {
    #[kani::ensures(result == Foo::A)]
    pub fn new() -> Foo {
        Foo::A
    }
}

#[kani::proof_for_contract(Foo::new)]
fn check() {
    let _ = Foo::new();
}

using the following command line invocation:

kani enum_ensures.rs -Zfunction-contracts

with Kani version: f10e61c

I expected to see this happen: Verification succeeds

Instead, this happened:

$ kani enum_ensures.rs -Zfunction-contracts
Kani Rust Verifier 0.51.0 (standalone)
error[E0425]: cannot find function `new_wrapper_faac06` in this scope
  --> enum_ensures.rs:10:5
   |
10 |     #[kani::ensures(result == Foo::A)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in the attribute macro `kani::ensures` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using the associated function on `Self`
   |
10 |     Self::#[kani::ensures(result == Foo::A)]
   |     ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
error: /home/ubuntu/git/kani/target/kani/bin/kani-compiler exited with status exit status: 1

Metadata

Metadata

Assignees

Labels

T-High PriorityTag issues that have high priorityZ-ContractsIssue related to code contracts[C] BugThis is a bug. Something isn't working.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions