You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(Debug)]enumFoo{Bar,Baz,}typeLoz = Foo;fnmain(){let y = Loz::Bar;println!("{:?}", y);}
On the stable channel the following error occurs:
<anon>:8:13: 8:21 error: type `Foo` does not implement any method in scope named `Bar`
<anon>:8 let y = Loz::Bar;
^~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101```
I think it's a somewhat tough question. The "integration" of enum variants and other kinds of associated items is, well, there isn't any, though it sort of feels like it'd be nice if there was. I certainly think is expected behavior for the moment, and I think that any fix would require some careful thought to be sure.
Yeah, this is definitely not a minor fix. I'd leave as is. I guess we could document better. I would only like to see a better error message if it can be done without making name resolution more awful.
That's even less likely to be fixed - it's a call to a constructor function, and Self isn't even present in the value namespace, so you can't be expected to do
I just hit this thing, when I wanted an alias of generic enum with concrete type parameter, as @mitchmindtree demonstrated in his example. I'm pretty fluent in Rust, yet I thought "WTF?!" and was confused for few minutes, then tried minimal example on playpen and then found this issue.
So apparently, it's not just confusing but also wastes time. I now have to rewrite things...
Reacted by Boscop, Joshua Worth, David Roundy, h-castle, pyfisch, Emilien Fugier, Boris Berman and Tim Süberkrüb
Activity
arielb1 commentedon Jun 13, 2015
typeonly creates a type alias - it does not change resolution. Maybe documentation should be improved through.arielb1 commentedon Jun 14, 2015
The error in nightly is better:
enum constructors are not associated items.
chris-morgan commentedon Aug 13, 2015
It seems to me that it is entirely reasonable to expect this to work. It’s not just a matter of documentation.
arielb1 commentedon Aug 13, 2015
@chris-morgan
Maybe. However, associated items work rather differently from resolve-items - e.g.
use Trait::Itemdoesn't work, but is the correct way with enums.steveklabnik commentedon Nov 5, 2015
/cc @rust-lang/lang, should this work, or should this give a better error?
nikomatsakis commentedon Nov 5, 2015
I think it's a somewhat tough question. The "integration" of enum variants and other kinds of associated items is, well, there isn't any, though it sort of feels like it'd be nice if there was. I certainly think is expected behavior for the moment, and I think that any fix would require some careful thought to be sure.
nrc commentedon Nov 5, 2015
Yeah, this is definitely not a minor fix. I'd leave as is. I guess we could document better. I would only like to see a better error message if it can be done without making name resolution more awful.
codyps commentedon Jan 12, 2016
Similarly, associated types too can resolve constructing functions, but not enum variants: http://is.gd/pnn7sC
It'd be very convenient to be able to think about enum variants in the same way we think about type constructing functions.
Rollup merge of rust-lang#32083 - nodakai:reference-scoped-enum-alias…
22 remaining items
leonardo-m commentedon Jul 7, 2017
Is this problem related?
alexreg commentedon Jul 8, 2017
Any progress on this yet?
arielb1 commentedon Jul 8, 2017
@leonardo-m
That's even less likely to be fixed - it's a call to a constructor function, and
Selfisn't even present in the value namespace, so you can't be expected to doachan1989 commentedon Mar 6, 2018
As a lowly Rust noob, +1 on this. It's entirely against the intuitive behaviour that you'd expect, given how structs work.
anirudhb commentedon Apr 4, 2018
Since an RFC has already been proposed, and #31179 implements this, it should be worth merging.
cc @nikomatsakis
Kixunil commentedon May 26, 2018
I just hit this thing, when I wanted an alias of generic enum with concrete type parameter, as @mitchmindtree demonstrated in his example. I'm pretty fluent in Rust, yet I thought "WTF?!" and was confused for few minutes, then tried minimal example on playpen and then found this issue.
So apparently, it's not just confusing but also wastes time. I now have to rewrite things...
petrochenkov commentedon Jan 14, 2019
This was implemented in #56225 and the tracking issue is #49683