Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uptype items do not work with enums #26264
Comments
This comment has been minimized.
This comment has been minimized.
|
|
arielb1
added
A-docs
A-diagnostics
and removed
A-docs
labels
Jun 13, 2015
This comment has been minimized.
This comment has been minimized.
|
The error in nightly is better:
enum constructors are not associated items. |
This comment has been minimized.
This comment has been minimized.
|
It seems to me that it is entirely reasonable to expect this to work. It’s not just a matter of documentation. |
This comment has been minimized.
This comment has been minimized.
|
Maybe. However, associated items work rather differently from resolve-items - e.g. |
This comment has been minimized.
This comment has been minimized.
|
/cc @rust-lang/lang, should this work, or should this give a better error? |
steveklabnik
added
the
A-lang
label
Nov 5, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
KiChjang
referenced this issue
Feb 2, 2016
Closed
Re-export IDL union typedefs instead of using type aliasing #9511
This was referenced Feb 10, 2016
nodakai
added a commit
to nodakai/rust
that referenced
this issue
Mar 6, 2016
nodakai
referenced this issue
Mar 6, 2016
Merged
reference.md: clarify the limitation of type alias on an enum #32083
nodakai
added a commit
to nodakai/rust
that referenced
this issue
Mar 8, 2016
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Mar 8, 2016
mitaa
referenced this issue
Apr 8, 2016
Closed
Accessing an enum's variants via a type alias. #32824
This comment has been minimized.
This comment has been minimized.
|
I posted a related issue earlier, but @mitaa kindly pointed me here, so I'll close that in favour of posting the parts of my issue that have not been covered here yet below. In examples like the one above this normally isn't a huge issue as it is possible to However, in practise I often come across cases where #[derive(Debug)]
pub enum Foo<T> { Bar(T), Baz }
pub type Loz = Foo<i32>;
pub fn qux() -> Loz {
Loz::Bar(0) // error
}
fn main() {
println!("{:?}", qux());
}Here I want to expose |
This comment has been minimized.
This comment has been minimized.
|
Another similarly-annoying case is in impls, as you can't do |
arielb1
added
the
T-lang
label
Apr 8, 2016
This comment has been minimized.
This comment has been minimized.
|
+1 on this not being very intuitive. Hit to today and took a bit to figure out what's going on. Being able to fill in partial types would be really nice, or at least a better error message that Enums can't be used with type. |
This comment has been minimized.
This comment has been minimized.
|
What's the latest on this? |
This comment has been minimized.
This comment has been minimized.
|
This is really unintuitive, especially as many crates define |
amluto
pushed a commit
to amluto/nfc-sys
that referenced
this issue
Sep 14, 2016
petrochenkov
referenced this issue
Nov 3, 2016
Closed
Tracking issue for Self and associated types in struct expressions and patterns #37544
petrochenkov
referenced this issue
Nov 12, 2016
Merged
[7/n] rustc: desugar UFCS in HIR and don't use DefMap for associated resolutions. #37676
petrochenkov
referenced this issue
Feb 19, 2017
Open
Enum associated functions can name-clash with variants, but cannot be called. #39946
petrochenkov
self-assigned this
Feb 19, 2017
petrochenkov
added
A-resolve
and removed
A-diagnostics
labels
Feb 19, 2017
petrochenkov
referenced this issue
Mar 5, 2017
Closed
Nonsequitur error message when trying to use Self in odd way #31168
steveklabnik
added
T-lang
and removed
A-lang
labels
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Jul 7, 2017
|
Is this problem related?
|
This comment has been minimized.
This comment has been minimized.
|
Any progress on this yet? |
This comment has been minimized.
This comment has been minimized.
|
That's even less likely to be fixed - it's a call to a constructor function, and struct S(u32);
impl S {
fn foo(&self) -> Self {
let make_self = Self;
make_self(Self.0);
}
} |
Mark-Simulacrum
added
the
C-feature-request
label
Jul 22, 2017
bluss
referenced this issue
Aug 23, 2017
Closed
`type X = ::Y` vs `use ::Y as X` mismatch if ::Y is a enum #44057
petrochenkov
referenced this issue
Sep 3, 2017
Closed
Can't refer to enum variant via Self keyword #44299
petrochenkov
referenced this issue
Nov 15, 2017
Open
Generics: Make enum variant syntax consistent with other types #2218
glandium
referenced this issue
Mar 5, 2018
Open
Error reporting when using enum variants of Self is not making any sense #48743
petrochenkov
referenced this issue
Mar 5, 2018
Open
Enum variants completely shadow inherent associated functions. #48758
This comment has been minimized.
This comment has been minimized.
achan1989
commented
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. |
This comment has been minimized.
This comment has been minimized.
|
Since an RFC has already been proposed, and #31179 implements this, it should be worth merging. |
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
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... |
AngelOfSol commentedJun 13, 2015
•
edited by apasel422
type items don't work with enums.
On the stable channel the following error occurs: