-
Notifications
You must be signed in to change notification settings - Fork 66
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
Reference return value with lifetime of self plus second parameter of same lieftime #134
Comments
The first thing to notice is that while Mockall can handle your first example, it doesn't handle it very well. It will only be possible to set expectations where the reference is |
Thank you for the explanation.
If the mocked returned reference is |
It's not that the returned reference is magically |
Sorry if I'm being dense. My point is, at least I could be allowed to provide static closures if other kind of closures don't work. But currently I cannot even provide static closures even though they should work because the mock code generation doesn't compile. This would not be a perfect solution because as you say some closures won't work but it is better than not being able to mock at all. |
Yes, that's correct. But what I haven't been sufficiently clear about is that, from the perspective of Mockall's internals, these two issues are actually very similar. Fixing #85 is at the very least a precondition to this issue. More likely, I think that #85 would probably go at least 90% of the way to getting what you want. That's my judgement based on how the implementation works, not based on what the user-visible capabilities are. |
In case someone finds this in the future. Here is a workaround that doesn't require changing your trait or mockall: pub struct StructWithReference<'a> {
reference: &'a (),
}
pub trait Trait {
fn foo<'a>(&'a self, b: &'a ()) -> StructWithReference<'a>;
}
#[cfg(test)]
mod mock {
use super::*;
#[mockall::automock]
pub trait Trait_ {
fn foo<'a>(&'a self, b: &()) -> StructWithReference<'a>;
}
impl Trait for MockTrait_ {
fn foo(&self, b: &()) -> StructWithReference {
Trait_::foo(self, b)
}
}
}
#[cfg(test)]
pub use mock::MockTrait_ as MockTrait; |
Thank you for making mockall.
As the docs say https://docs.rs/mockall/0.7.1/mockall/#reference-return-values
mockall supports this
If we add another parameter with the same lifetime the program no longer compiles
I understand that this might be expected. I am reporting this in case there is an easy fix inside of mockall and this case was merely overlooked.
The text was updated successfully, but these errors were encountered: