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
A struct inside an enum generates a type identifier (as it does outside when used outside an enum).
enum S { C {a:int, b:int}};
enum C {};
t.rs:10:4: 10:13 error: duplicate definition of type `C`
t.rs:10 enum C {};
^~~~~~~~~
t.rs:9:13: 9:29 note: first definition of type `C` here
t.rs:9 enum S { C {a:int, b:int}};
^~~~~~~~~~~~~~~~
In particular the following declaration doesn't typecheck.
enum S { S {a:int, b:int}};
t.rs:6:13: 6:29 error: duplicate definition of type `S`
t.rs:6 enum S { S {a:int, b:int}};
^~~~~~~~~~~~~~~~
t.rs:6:4: 6:30 note: first definition of type `S` here
t.rs:6 enum S { S {a:int, b:int}};
This is inconsistent with the general case in which such is allowed. E.g., both declarations below type check, despite type and value constructors having the same identifier:
enum S { S(int, int) }
struct S {a:int, b:int};
As a sidenote, we can't create values of these generated types even if wished to do so for some reason, since the value constructor associated with the struct field is set to create values of the enum type.
enum S { C {a:int, b:int} };
let k : C = C{a:0, b:0};
t.rs:10:12: 10:13 error: found value name used as a type: DefVariant(syntax::ast::DefId{crate: 0, node: 7}, syntax::ast::DefId{crate: 0, node: 14}, true)
t.rs:10 let k : C = C{a:0, b:0};
My tests were performed on v0.8, but the bug was confirmed to be present in 0.9pre. Using Linux, OpenSUSE 13.1
The text was updated successfully, but these errors were encountered:
This is now actually by design, RFC #234 places enum variants into the type namespace as well as the value namespace. (This was not the case when this issue was filed, though, so was definitely worth a bug then; thanks!)
The bad error message you note is still an issue, but this is covered more specifically by #17546, so I'm closing this.
A struct inside an enum generates a type identifier (as it does outside when used outside an enum).
In particular the following declaration doesn't typecheck.
This is inconsistent with the general case in which such is allowed. E.g., both declarations below type check, despite type and value constructors having the same identifier:
As a sidenote, we can't create values of these generated types even if wished to do so for some reason, since the value constructor associated with the struct field is set to create values of the enum type.
My tests were performed on v0.8, but the bug was confirmed to be present in 0.9pre. Using Linux, OpenSUSE 13.1
The text was updated successfully, but these errors were encountered: