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

Derive Arbitrary for types with lifetimes #50

Closed
mcy opened this issue Jun 18, 2020 · 3 comments
Closed

Derive Arbitrary for types with lifetimes #50

mcy opened this issue Jun 18, 2020 · 3 comments

Comments

@mcy
Copy link

mcy commented Jun 18, 2020

derive(Arbitrary) currently won't derive Arbitrary if the type has a lifetime parameter in it. Most of the time this is fine, because Arbitrary: 'static. However, it seems like it would be possible to implement Arbitrary if all of the type parameters were set to 'static. This is somewhat inconsistent with Cow<'static, impl Arbitrary>: Arbitrary.

I haven't looked into how hard this would be, but I'm willing to mail a change adding this (maybe behind a Cargo feature?) if maintainers would consider it a useful addition.

@fitzgen
Copy link
Member

fitzgen commented Jun 18, 2020

Yeah, if the lifetime is 'static then the derive should handle it.

The derive's code is in ./derive/src/lib.rs. I'm not sure off the top of my head what would need to change in there to support this.

@mcy
Copy link
Author

mcy commented Jun 18, 2020

I think I didn't phrase what I meant correctly. I want the following behavior:

#[derive(Arbitrary)]
struct Foo<'a, 'b, ...> { ... }
// Generated impl:
impl Arbitrary for Foo<'static, 'static, ...> { ... }

I believe that this should be "easy", by blindly rewriting every lifetime into 'static. I would have liked to write

#[derive(Arbitrary)]
type StaticFoo = Foo<'static, 'static, ...>;

I feel this is less surprising syntax but not something proc macros can do AFAIK, since they don't have type information available.

@frewsxcv
Copy link
Member

Done in #63

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

No branches or pull requests

3 participants