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

"[Lifetime] parameter 'a is never used" error on mixed enums #10

Open
brundonsmith opened this issue Nov 9, 2022 · 0 comments
Open

Comments

@brundonsmith
Copy link

brundonsmith commented Nov 9, 2022

#[derive(EnumVariantType)]
enum Foo<'a> {
    NoLifetimeVariant(usize),
    LifetimeVariant(&'a str),
}
error[E0392]: parameter `'a` is never used
  --> src/main.rs:36:10
   |
36 | enum Foo<'a> {
   |          ^^ unused parameter
   |
   = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

Seen on v0.3.1

If NoLifetimeVariant is removed or EnumVariantType is removed, the error goes away. I think (though I haven't looked at the library source code or the expanded macro output to make sure) what's happening here is it's trying to give the <'a> to every generated struct, regardless of whether or not it gets used inside that variant.

I understand this may be a difficult thing to solve at the macro level, but I thought I'd report it anyway. In the meantime I'm probably going to work around it using PhantomData

One fix you might be able to implement, which might be easier than inspecting each variant to see if it uses a lifetime, would be to provide an annotation along the lines of #[evt(skip_lifetime('a))] or something that we could manually assign to the problematic variants

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

1 participant