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

Support for anonymous lifetimes #87

Closed
DGolubets opened this issue Dec 1, 2019 · 9 comments · Fixed by #173
Closed

Support for anonymous lifetimes #87

DGolubets opened this issue Dec 1, 2019 · 9 comments · Fixed by #173
Labels
enhancement New feature or request

Comments

@DGolubets
Copy link

DGolubets commented Dec 1, 2019

This example doesn't work:

struct X<'a>(&'a u32);

#[automock]
trait Foo {
    fn foo(&self) -> X<'_>;
}
`'_` is a reserved lifetime name

If I specify the lifetime explicitly it does.

@asomers
Copy link
Owner

asomers commented Dec 1, 2019

Hm, while I see your point, I don't think the benefit to this feature is very great, since the workaround is trivial. Is there any method that can't be mocked just by naming the liftetimes? If not, then I'm not going to give this feature much priority.

@DGolubets
Copy link
Author

Is there any method that can't be mocked just by naming the liftetimes?

Hopefully not :)

I agree it's not a priority.
Just a little annoying that it makes the code more verbose than required.
But yeah, nothing critical.

@asomers asomers added the enhancement New feature or request label Dec 6, 2019
@MOZGIII
Copy link

MOZGIII commented Dec 18, 2019

async_trait workaround kind of needs this

@asomers
Copy link
Owner

asomers commented Dec 18, 2019

How so, @MOZGIII ?

@MOZGIII
Copy link

MOZGIII commented Dec 18, 2019

#75 (comment)
Here you suggest using 'static, while it really can be just '_ 😄
But that's out of date anyways.

@asomers
Copy link
Owner

asomers commented Dec 18, 2019

If that's your only concern then I wouldn't say need since you can always specify a named lifetime, just like in https://github.com/asomers/mockall/blob/master/mockall/tests/mock_generic_method_returning_nonstatic.rs .

@MOZGIII
Copy link

MOZGIII commented Dec 18, 2019

That would require changing the trait. You can’t always do that, so it’s not a fair solution.

@asomers
Copy link
Owner

asomers commented Dec 18, 2019

patches welcome.

@asomers
Copy link
Owner

asomers commented Aug 22, 2020

Ok, I have this working. However, I still don't really understand the need. Can you give an example of a real-world trait with such a method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants