Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roypat opened this issue Jun 13, 2023 · 4 comments
Assignees
Labels
[C] Bug This is a bug. Something isn't working.
Milestone

Comments

@roypat
Copy link

roypat commented Jun 13, 2023

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)
@roypat roypat added the [C] Bug This is a bug. Something isn't working. label Jun 13, 2023
@feliperodri feliperodri self-assigned this Jun 13, 2023
@celinval celinval added this to the Stubbing milestone Jun 13, 2023
@celinval
Copy link
Contributor

Thanks for reporting this issue @roypat. I believe this is a duplicate of #1997. Let me know if the original issue covers your use case, and we can close this one. Thanks!

@celinval
Copy link
Contributor

That said, I wonder if we should just split #1997 into two issues. We can use #1997 to track disambiguation using the qualified path type and use this issue to track stubbing trait methods without ambiguous definition. @feliperodri any thoughts?

@roypat
Copy link
Author

roypat commented Jun 14, 2023

Thanks for reporting this issue @roypat. I believe this is a duplicate of #1997. Let me know if the original issue covers your use case, and we can close this one. Thanks!

Ahhh, right, yes #1997 does indeed look like a general case of this. Sorry about that! Feel free to close as duplicate :)

@celinval
Copy link
Contributor

BTW, @feliperodri I wonder if we can at least improve the error message now. We could add a note saying that trait methods are not supported.

@celinval celinval assigned celinval and unassigned feliperodri Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants