Skip to content

[Stubbing] Stubbing of trait method results in "unable to find <...> inside struct <...>" #2524

@roypat

Description

@roypat

I tried this code:

    trait Foo {
        fn foo() -> usize;
    }

    struct Bar;

    impl Foo for Bar {
        fn foo() -> usize {
            1
        }
    }

    fn foo_stub() -> usize {
        2
    }

    #[kani::proof]
    #[kani::stub(Bar::foo, foo_stub)]
    fn my_proof() {
        assert_eq!(Bar::foo(), 2)
    }

using the following command line invocation:

cargo kani  --enable-unstable --enable-stubbing --harness my_proof

with Kani version: 0.29.0

I expected to see this happen: Verification to pass, with the implementation of the foo trait method for Bar being stubbed out.

Instead, this happened:

error: failed to resolve `Bar::foo`: unable to find `foo` inside struct `Bar`
   --> <...>
    |
559 |     #[kani::stub(Bar::foo, foo_stub)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the attribute macro `kani::stub` (in Nightly builds, run with -Z macro-backtrace for more info)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Z-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