-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type items do not work with enums #26264
Comments
|
The error in nightly is better:
enum constructors are not associated items. |
It seems to me that it is entirely reasonable to expect this to work. It’s not just a matter of documentation. |
Maybe. However, associated items work rather differently from resolve-items - e.g. |
/cc @rust-lang/lang, should this work, or should this give a better error? |
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. |
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. |
Cf. rust-lang#26264 Signed-off-by: NODA, Kai <[email protected]>
…, r=nikomatsakis reference.md: clarify the limitation of type alias on an enum Tentatively define the current behavior as the specification. Cf. rust-lang#26264, rust-lang#28556, rust-lang#30936
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 |
Another similarly-annoying case is in impls, as you can't do |
+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. |
What's the latest on this? |
This is really unintuitive, especially as many crates define |
This avoids severe annoyance due to rust-lang/rust#26264
Is this problem related?
|
Any progress on this yet? |
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);
}
} |
As a lowly Rust noob, +1 on this. It's entirely against the intuitive behaviour that you'd expect, given how structs work. |
Since an RFC has already been proposed, and #31179 implements this, it should be worth merging. |
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... |
type items don't work with enums.
On the stable channel the following error occurs:
The text was updated successfully, but these errors were encountered: