Skip to content

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

@brundonsmith

Description

@brundonsmith
#[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions