-
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
use-ing anyhow::Ok interferes with generated code #388
Comments
That's a very good guess. BTW, you can see the generated code by setting MOCKALL_DEBUG=1 when you build. Would you be able to check it? |
Sure! Relevant bit of generated code: {
Default, Expired,
Mut(Box < dyn FnMut() -> Result < (), Error > + Send >),
MutSt(:: mockall :: Fragile < Box < dyn FnMut() -> Result < (),
Error > >>),
Once(Box < dyn FnOnce() -> Result < (), Error > + Send >),
OnceSt(:: mockall :: Fragile < Box < dyn FnOnce() -> Result < (),
Error > >>), _Phantom(Box < dyn Fn() + Send >)
} impl Rfunc
{
fn call_mut(& mut self,) -> std :: result :: Result < Result < (),
Error >, & 'static str >
{
match self
{
Rfunc :: Default =>
{
use :: mockall :: ReturnDefault ; :: mockall ::
DefaultReturner :: < Result < (), Error > > ::
return_default()
}, Rfunc :: Expired =>
{ Err("called twice, but it returns by move") }, Rfunc ::
Mut(__mockall_f) => { Ok(__mockall_f()) }, Rfunc ::
MutSt(__mockall_f) => { Ok((__mockall_f.get_mut()) ()) },
Rfunc :: Once(_) =>
{
if let Rfunc :: Once(mut __mockall_f) = mem ::
replace(self, Rfunc :: Expired) { Ok(__mockall_f()) } else
{ unreachable! () }
}, Rfunc :: OnceSt(_) =>
{
if let Rfunc :: OnceSt(mut __mockall_f) = mem ::
replace(self, Rfunc :: Expired)
{ Ok((__mockall_f.into_inner()) ()) } else
{ unreachable! () }
}, Rfunc :: _Phantom(_) => unreachable! ()
}
}
} |
I can also confirm that if I paste the generated code into my IDE I get the error and if I change |
asomers
added a commit
that referenced
this issue
Jun 28, 2022
The `anyhow` create defines a function by this name, and the proc-macro generated code was picking it up instead of the standard Result::Ok . Fixes #388
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm filing the issue mostly because this results in a somewhat non-obvious error message.
Repro:
Compiler error:
Changing the first line to
use anyhow::Error;
causes the issue to go away.It seems like some of the generated code (like
fn call_mut(&mut self) -> std::result::Result<Result<(), Error>, &'static str>
) explicitly referencesstd::result::Result
while other bits (like returningOk(__mockall_f())
) rely on nobody being silly enough to import their ownOk
.Hopefully fixing this is as simple as having the generated code return a fully-qualified
std::result::Result::Ok
instead of justOk
.The text was updated successfully, but these errors were encountered: