-
Notifications
You must be signed in to change notification settings - Fork 69
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
error: proc macro panicked
on mocking GRPC interface generated by tonic
#637
Comments
The problem here is that you didn't copy the trait definition into the But not all hope is lost! There is precedent for mocking macros like this. Mockall contains some special case code to handle BTW, for better error messages, build Mockall with the "nightly" crate feature. |
Thanks for your reply! I didn't think about the outside-in expansion of macros, that makes sense. It appears that As for nightly, I presume it also requires a nightly compiler? Or is this purely an experimental option for mockall itself? |
Yes, the "nightly" crate feature requires a nightly compiler. If |
I have been looking at this and I can't see how to idiomatically define a But that means I need to mock Meanwhile the documentation suggests something easier might be done in https://docs.rs/mockall/latest/mockall/index.html#impl-future but there isn't any clear example for Stream, nor is it obvious how to do this with associated types. Searching the docs yield no results for "Stream" at all, likely because rustdoc doesn't do full text search... And |
Here's an example for
But if I understand correctly, your real problem is that the trait requires your method to return some specific type that implements |
Yeah that is correct, sorry I probably ended up redacting too much (out of caution with a proprietary code base). I basically have a code-generated trait like: trait A {
type SomeType: Stream<Item = ...> + Send + 'static;
fn someFn(...) -> SomeType;
} To mock that does, it does indeed seem I need to name a specific type. |
If I use a GRPC subscription, generate rust bindings with tonic and try to mock that I get
This seems like an internal error in mockall. I have created a minimal (or at least somewhat minimal) reproducer, the full cargo project is attached, but the code is:
Here is the repro project (the above code + the needed dependencies in Cargo.toml basically): mockall_panic_repro.tar.gz
This happens with mockall 0.13.1, I have not checked if it happens with older versions.
If I remove the
type
and only try to mock the functions (not included in the small reproducer) it complains as well:So it seems associated type support is a bit lacking when using
mock!
, the error message if you just blindly copy the trait definition into the mock! results in a very confusing error message. It would be good to have something that points at the appropriate line and says something like "ADT = SomeType expected, found ADT definition" or similar.The text was updated successfully, but these errors were encountered: