error[E0599]: no associated item named `A` found for type `SomeEnum` in the current scope
--> <anon>:11:9
|
11 | Self::A(5.0)
| ^^^^^^^
I know that rust had problems with using Self in constructor-like functions - is this an open issue right now? All I want to do is to avoid using my enums name. Rust obviously detects that I want to use SomeEnum, but for some reason, it doesn't find the enum variant.
In the meantime, perhaps the following would appeal to you:
pub fn new() -> Self {
use SomeEnum::*;
A(5.0);
}
This obviously doesn't help in the simple case above, but if your new function referred to more of the variants, then it would cut down the # of places you refer to the enum name.
Allowing code as you write would lead to confusion. The Self:: identifies to the reader/compiler that the next identifier is an associated type. There is nothing to stop an identifier being of the same name as a structures members name.
This is part of issue 26264 and its duplicate 31168. The language team has agreed that this should be fixed, but it hasn't happened yet because of some open design and implementation issues.