Hello everyone.
Having an enum like this:
enum Foo<'a> {
A(&'a u8),
B(Cow<'a, u8>),
C(u8),
D { x: u8 },
}
I can create variants of the enum using the syntax Foo::<'a>::X ...
, where "X" is "A", "B" or "C", but not "D", for which I have to write just Foo::D ...
E.g.
fn foo<'a>(x: &'a u8) {
let val = Foo::<'a>::A(&x);
let val = Foo::<'a>::B(Cow::Borrowed(x));
let val = Foo::<'a>::C(*x);
// let val = Foo::<'a>::D { x: *x }; // Error: lifetime arguments are not allowed on variant `D`
let val = Foo::D { x: *x }; // This compiles.
}
(Btw it doesn't matter that D doesn't use 'a
, only the fact that it's a struct-like variant matters).
The question is: why is it so? Is it a bug in the compiler that should be reported?
To be clear, I've hit upon this issue when using a 3rd-party derive macro, which produces these Foo::<'a>::X
calls. I don't think the macro itself can get rid of the turbofish, because it has to support all kinds of generic parameters on enums.
So the only solution for me is to refactor the enum itself, so that it doesn't use struct-like variants, which is a bit annoying.